Here is what I have done so far:
Code:
#include<stdio.h>
#include<math.h>
int main()
{
int x,n,i,f;
printf("Please enter an integer: \n");
scanf("%d",&x);
n=10;
f=x;
i=0;
while((f/n)>0)
{
if((f%10)==7)
{
i+=1;
}
f=f/10;
}
printf("The number %d has %d sevens.",x,i);
}
The only problem with this code is that it does not count the first "seven" in the integer, for example:
If I input "77777", it will say that it has 4 sevens. I know here the problem is, I just don't know how to overcome it. Any ideas?