.通过编程实现,统计1~n有多少个9 (n通过参数传入)

xiaoxiao2021-02-28  129



#include<stdio.h>

int count9(int n) {         int i,r,temp;         int j=0;         for(i=1;i<=n;i++)         {                 temp=i;                 while(temp!=0)                 {                         r=temp;                         temp=temp/10;                         if(r==9)                         {                                 j++;                         }                 }         }         return j; } int main() {         int n,m;         printf("input a number:\n");         scanf("%d",&n);         m=count9(n);         printf("The number of 9 is:%d\n",m);         return 0; }

转载请注明原文地址: https://www.6miu.com/read-42755.html

最新回复(0)