-
Notifications
You must be signed in to change notification settings - Fork 0
/
0803_try.c
50 lines (40 loc) · 1012 Bytes
/
0803_try.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*Checks numbers for repeated digits*/
#include <stdio.h>
#include <stdbool.h>
int
main (int argc, char *argv[])
{
bool digit_seen[10] = {false};
int digit;
long n, i = 0;
/* 首先将数读入一个数组,但是这里如何声明数组是个问题?*/
printf("Enter numbers(<=0 to terminate): ");
do
{
scanf("%ld", &n[i]);
i++;
} while (n[i-1] > 0);
/* 采用for循环,对数组中得每个数字进行判断是否有重复的数字 */
for (i = 0; n[i] > 0; i += 1)
{
while (n[i] > 0)
{
digit = n[i] % 10;
if (digit_seen[digit])
{
break;
}
digit_seen[digit] = true;
n[i] /= 10;
}
if (n[i] > 0)
{
printf("%ld has repeated digit(s)\n.", n[i]);
}
else
{
printf("No repeated digit\n");
}
}
return 0;
}