Modify the below program so that it shows which digits (if any) were repeated: E
ID: 3621911 • Letter: M
Question
Modify the below program so that it shows which digits (if any) were repeated:
Ex). Enter a number: 939577
Repeated Digit(s): 7 9
/* Checks number for repeated digtis*/
#include /*C99 only*/
#include
int main (void)
{
bool digit_seen [10]
int digit;
long n;
printf ("Enter a number: ");
scanf ("%1d", &n);
while (n > 0) {
digit = % 10;
if (digit_seen [digit])
break;
digit_seen [digit] = true;
n / = 10;
}
if (n > 0)
printf ("Repeated digit ");
else
printf ("No repeated digit ");
return 0;
}
Need help modifying the above program in C-Language (can't be C# or C++)
Explanation / Answer
please rate - thanks
/* Checks number for repeated digtis*/
#include <stdio.h>
#include <conio.h>
int main (void)
{
int digit_seen [10]={0};
int digit;
long n;
printf ("Enter a number: ");
scanf ("%ld", &n);
while (n > 0) {
digit = n% 10;
digit_seen[digit]++;
n /= 10;
}
printf("repeated digit(s): ");
for(digit=0;digit<10;digit++)
if(digit_seen[digit]>1)
printf ("%d ",digit);
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.