To give you more of a challenge with a number's digits, let's try counting how many of a certain digit is present on a given number.
Let's start coding!
Instructions:
#include<stdio.h>
int main(){
int number,digit,count=0;
printf("Enter the integer and a non-zero positive integer: ");
scanf("%d%d",&digit,&number);
while(number>0){
if (number % 10 == digit){
count +=1;
}
number = number/10;
}
printf("%d",count);
getchar();
getchar();
return 0;
}
Comments
Leave a comment