輸入n1 n2 m 三個數,1<m<9,若m不在范圍內輸出err,n1,n2為數字范圍,依次輸出從n1數到n2,遇到能被m整除的數或數字中包含m的數,以_代替,數字間以空格分隔。
球球大佬們,孩子做不出來了
uj5u.com熱心網友回復:
void Test(void)
{
int n1 = 0;
int n2 = 0;
int m = 0;
scanf_s("%d", &n1);
scanf_s("%d", &n2);
scanf_s("%d", &m);
if (m <= 1 || 9 <= m || n2 <= n1)
{
printf("err\r\n");
return;
}
for (int i = n1, j = 0; i < n2 + 1; ++i, ++j)
{
if (i % m == 0)
{
printf("_ ");
}
else
{
int bit = 0;
int num = i;
while (num != 0)
{
bit = num % 10;
num /= 10;
if (bit == m)
break;
}
if (bit == m)
printf("_ ");
else
printf("%d ", i);
}
if ((j + 1) % 10 == 0)
printf("\r\n");
}
printf("\r\n");
}
12 210 5
12 13 14 _ 16 17 18 19 _ 21
22 23 24 _ 26 27 28 29 _ 31
32 33 34 _ 36 37 38 39 _ 41
42 43 44 _ 46 47 48 49 _ _
_ _ _ _ _ _ _ _ _ 61
62 63 64 _ 66 67 68 69 _ 71
72 73 74 _ 76 77 78 79 _ 81
82 83 84 _ 86 87 88 89 _ 91
92 93 94 _ 96 97 98 99 _ 101
102 103 104 _ 106 107 108 109 _ 111
112 113 114 _ 116 117 118 119 _ 121
122 123 124 _ 126 127 128 129 _ 131
132 133 134 _ 136 137 138 139 _ 141
142 143 144 _ 146 147 148 149 _ _
_ _ _ _ _ _ _ _ _ 161
162 163 164 _ 166 167 168 169 _ 171
172 173 174 _ 176 177 178 179 _ 181
182 183 184 _ 186 187 188 189 _ 191
192 193 194 _ 196 197 198 199 _ 201
202 203 204 _ 206 207 208 209 _
請按任意鍵繼續. . .
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/225727.html
標籤:C語言
上一篇:一道C語言的題,救救菜鳥我吧
