您的位置:首页 > 其它

for循环练习题(1 ,判断任意一个数是91的多少倍 2,编写程序实现给定一个整数判断它从0到这个整数中间出现多少次9的次数)...

2018-12-05 11:28 218 查看

for循环练习题(1 ,判断任意一个数是91的多少倍 2,编写程序实现给定一个整数判断它从0到这个整数中间出现多少次9的次数)

 1 //判断任意一个数是9的多少倍

2 #include <stdio.h> 3 #include <stdlib.h> 4 int main() 5 { 6 printf("请输入任意一个数\n"); 7 8 int c, a, b; 9 scanf_s("%d", &c); 10 printf("它对9的倍数是:\n"); 11 if (c >=9){ 12 13 a = c / 9; 14 15 printf("%d\n", a); 16 } 17 else{ 18 printf("0\n"); 19 } 20 system("pause"); 21 return 0; 22 }

 

 

 

 

 

 

 

 

 

 

1 //编写程序实现给定一个整数判断它从0到这个整数中间出现多少次9的次数
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 int main()
6 {
7
8     int i;
9     int start, end;
10     int l = 1;
11 //temp的意义在于将i的值储存在temp中,用temp去模10余10,而i用于累加,二者不能重复
12     int temp;
13     printf("亲爱的用户您好,为了计算您要的结果,请您输入任意一个您想要的范围O(∩_∩)O\n");
14     scanf_s("%d %d", &start,&end);
15     printf("您要的结果如下:\n");
16     int count = 0;
17 //for用来数数,一个数字一个数字过,while相当于计数器,计一共有多少个这样的数
18     for (i = start; i <= end; i++){
19
20         temp = i;
21         while (temp > 0){
22             if (temp % 10 == 9){
23                 count++;
24             }
25             temp = temp / 10;
26
27             }
28         }
29     printf("%d\n", count);
30         system("pause");
31
32     return 0;
33 }
34 //测试发现大概计算范围到1~一千万左右,再往上写无法计算结果

 

posted @ 2018-12-05 11:28 核桃圆 阅读(...) 评论(...) 编辑 收藏
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐