Instructions:
Input
1. First integer
2. Second integer
Output
The first line will contain a message prompt to input the first integer.
The second line will contain a message prompt to input the second integer.
The last line contains the number of times the first integer occurred in the digits of the second integer.
Enter·the·first·integer·(0·-·9):·2
Enter·the·second·integer:·124218
Occurrences·=·2
#include <stdio.h>
int main()
{
int n1, n2;
int count = 0;
printf("Enter the first integer (0 - 9): ");
scanf("%d", &n1);
printf("Enter the second integer: ");
scanf("%d", &n2);
while (n2 != 0)
{
if (n1 == n2 % 10)
count++;
n2 /= 10;
}
printf("Occurrences = %d\n", count);
return 0;
}
Comments
Leave a comment