滴水逆向联盟
标题:
基于visual Studio2013解决C语言竞赛题之1017次数
[打印本页]
作者:
大灰狼
时间:
2014-8-29 09:15
标题:
基于visual Studio2013解决C语言竞赛题之1017次数
题目
download.png
(65.73 KB, 下载次数: 417)
下载附件
保存到相册
2014-8-29 09:15 上传
解决代码及点评
<pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">/*
功能:有人说在400, 401, 402, ...499这些数中4这个数字共出现112次,请编程序判定这
种说法是否正确。若正确请打印出'YES',否则打印出'NO'及4的出现次数
时间:15:27 2013/10/24
*/
#include<stdio.h>
#include<stdlib.h>
void main()
{
int sum=0; //计数器
for (int i = 400; i <= 499; i++) //遍历400-499
{
int b1 = i % 10; //个位数
int b2 = i / 10 % 10; //十位数
int b3 = i / 100; //百位数
if (b1 == 4)sum++; //每一位数等于4sum=sum+1;
if (b2 == 4)sum++;
if (b3 == 4)sum++;
}
if (sum == 112) //判断sum是否等于112
{
printf("Correctly!!! the number \"4\" it's aways appeared %d times",sum);
}
else
{
printf("Incorrectly!!!,totally appeares %d times!!!!",sum);
}
system("pause");
}</pre><br></pre></pre></pre>
欢迎光临 滴水逆向联盟 (http://dtdebug.com/)
Powered by Discuz! X3.2