I have this code which finds occurrence of number from numbers entered by user. My question is how to firstly enter numbers by user and then ask user to find his number in the sequence. I'm sorry if this question is stupid, but I'm just a beginner trying to teach myself how to program :) Thank you so much for your help!
This is my current code:
int main()
{
int num, remainder, k, count = 0;
printf("Which number do you want to find: \n");
scanf("%d", &k);
while(1)
{
printf("Enter numbers(end by pressing 0): ");
scanf("%d", &num);
remainder=num;
if(remainder==k)count++;
if(remainder==0) break;
}
printf("\Number %d occurs %d times.\n", k, count);
getch();
return 0;
}
This is what I tried:
int main()
{
int num, remainder, k, count = 0;
while(1)
{
printf("Enter numbers(end by pressing 0): ");
scanf("%d", &num);
remainder=num;
if(remainder==k)count++;
if(remainder==0) break;
}
printf("Which number do you want to find: \n");
scanf("%d", &k);
printf("\Number %d occurs %d times.\n", k, count);
getch();
return 0;