欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-01-28 10:18:52
#include int main() { int num,hundred,ten,unit,count=0; for(num=1;num<=1...
#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;
}