What's wrong with my program is that it keeps on adding the repeated digits to the occurrences. I want it to go back to zero after having entered the first number.
Code:
#include <stdio.h>
#define DIGIT 10
Here's my code so far:
main(){
long long int number=0;
int digit, i=0;
int digit_seen[10]={0};
printf("Digit Occurence Calculator\n\n");
while(){
printf("Enter a number:");
scanf("%lld", &number);
if(number<=0){
break;
}
while (number>0){//break up the digit
digit=number%10; //get the last digit
digit_seen[digit]++;//record that you see the number appear once
number=number/10;
}
printf("\nDigits: 0 1 2 3 4 5 6 7 8 9");
printf("\nOccurences:");
for(i=0; i<=9; i++){;
printf("%d ", digit_seen[i]);
}
printf("\n\n");
}
return 0;
}
Any help is greatly appreciated.