Name this program aligits.e- This program reads a single integer from standard i
ID: 3870663 • Letter: N
Question
Name this program aligits.e- This program reads a single integer from standard input and determines whether or not any of the digits in that number occur more than once. Two sample executions are Enter a number 12345 No duplicate digits found Enter a number: 314159 Duplicate digits found. Hints: Set up a loop that runs as long as your number is greater than zero . In the loop, you can extract the last (ones) digit of a number by using the mod operator,% After processing the one's digit, divide the number by 10 and then repeat your loopExplanation / Answer
#include <stdio.h>
int main()
{
int a[10]={0,0,0,0,0,0,0,0,0,0};
int n, found = 0;
int r,i;
printf("Enter a number: ");
scanf("%d", &n);
while(n!=0){
r = n % 10;
a[r]+=1;
if(a[r] > 1){
found = 1;
break;
}
n=n/10;
}
if(found==1) {
printf("Duplicate digits found ");
} else {
printf("No duplicate digits found ");
}
return 0;
}
output:
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.