码迷,mamicode.com
首页 > 编程语言 > 详细

C语言:编写程序数一下 1到 100 的所有整数中出现多少次数字 9

时间:2015-10-07 23:07:44      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:c语言:编写程序数一下 1到 100 的所有整数中出现多少次数字 9   计算整数出现次数   

#include <stdio.h>
int main()
{
 int num,hundred,ten,unit,count=0;
 for(num=1;num<=100;num++)
 { hundred=num/100;
  ten=(num-hundred*100)/10;
  unit=num-hundred*100-ten*10;
  if(hundred==9)
  {
   count++;
  }
   if(ten==9)
  {
   count++;
  }
  if(unit==9)
  {
   count++;
  }
 }
 printf("9出现的个数:\n%d",count);
 return 0;
}

C语言:编写程序数一下 1到 100 的所有整数中出现多少次数字 9

标签:c语言:编写程序数一下 1到 100 的所有整数中出现多少次数字 9   计算整数出现次数   

原文地址:http://10740184.blog.51cto.com/10730184/1700640

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!