码迷,mamicode.com
首页 > 其他好文 > 详细

求符合给定条件的整数集

时间:2019-05-30 17:52:00      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:main   ++   int   clu   unit   return   pre   条件   整数   

 1 /*
 2     求符合给定条件的整数集
 3 */
 4 
 5 #include <stdio.h>
 6 
 7 int main()
 8 {
 9     int n;
10     int cnt = 0;
11     int hundred, ten, unit;
12 
13     scanf_s("%d", &n);
14     
15     for (int i = 100; i < 1000; i++)
16     {
17         hundred = i / 100;
18         ten = i % 100 / 10;
19         unit = i % 10;
20 
21         if (hundred == ten || ten == unit || hundred == unit)
22         {
23             continue;
24         }
25 
26         if (hundred >= n && hundred <= n+3)
27         {
28             if (ten >= n && ten <= n + 3)
29             {
30                 if(unit >= n && unit <= n + 3)
31                 {
32                     printf("%d", i);
33                     cnt++;
34                     if (cnt < 6)
35                     {
36                         printf(" ");
37                     }
38                     else
39                     {
40                         if (cnt == 6)
41                         {
42                             printf("\n");
43                             cnt = 0;
44                         }
45                     }
46                 }
47             }            
48         }
49     }
50 
51     return 0;
52 }

 

求符合给定条件的整数集

标签:main   ++   int   clu   unit   return   pre   条件   整数   

原文地址:https://www.cnblogs.com/2018jason/p/10950660.html

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