Using a while loop, i need count how many of the first integer (0-9) is present in the digits of the second inputted integer and print the result.
input sample: 2, 124218
output sample: 2
this is my code below:
#include<stdio.h>
int main() {
int a;
int num;
int i;
int rev = 0;
int reminder;
int count = 1;
int ans;
int last;
scanf("%d",&a);
scanf("%d", &num );
while(num!=0)
{
reminder=num%10;
rev=rev*10+reminder;
num/=10;
if(a==reminder){
ans++;
last = ans%10;
printf("%d", last);
}
count++;
}
return 0;
}