70,037
社区成员
发帖
与我相关
我的任务
分享#include<stdio.h>
int main(void)
{
int digit_seen[10] = { 0 };//, repeated_digit[10] = { 0 };
int digit,i=0, flag = 0;//j=0;
long n;
printf("Enter a number: ");
//scanf_s("%ld", &n);
scanf("%ld", &n);
while (n > 0) {
digit_seen[n % 10]++;
n /= 10;
/*
digit = n % 10;
digit_seen[digit] = digit;
if (digit_seen[digit] == digit)
{
repeated_digit[j] = digit;
j++ ;
}
n /=10;
*/
}
for (i = 0; i < 10; i++)
if (digit_seen[i] > 1) {
if (flag == 0)
printf("Repeated digit\n");
printf("%d ", i);
flag = 1;
}
if (flag == 0)
printf("No repeated digit\n");
else
putchar(10);
/*
if (j > 0)
{
printf("Repeated digit\n");
for (i = 0; i <= j; i++)
{
printf(" %d", repeated_digit[j]);
}
}
else
printf("No repeated digit\n");
*/
return 0;
}