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:
Input
A line containing two integers separated by a space.
2·124218
Output
A line containing an integer.
2
#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