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


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

    2 #include <stdio.h> 3 #include <stdlib.h> 4 int main() 5 { 6 printf("请输入任意一个数 "); 7 8 int c, a, b; 9 scanf_s("%d", &c); 10 printf("它对9的倍数是: "); 11 if (c >=9){ 12 13 a = c / 9; 14 15 printf("%d ", a); 16 } 17 else{ 18 printf("0 "); 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
    ");
    14     scanf_s("%d %d", &start,&end);
    15     printf("您要的结果如下:
    ");
    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
    ", count);
    30         system("pause");
    31 
    32     return 0;
    33 }
    34 //测试发现大概计算范围到1~一千万左右,再往上写无法计算结果

     

  • 相关阅读:
    C# 使用布尔操作符
    C# 复合赋值操作符
    C# while语句
    C# do while语句
    datatabe 与string
    打开外部程序并
    group by 显示
    GROUP by 方法  C#
    屏幕取色
    C#简单继承示例详解——快速入门
  • 原文地址:https://www.cnblogs.com/hetaoyuan/p/10068822.html
Copyright © 2020-2023  润新知