Answer to Question #343968 in C for Ken

Question #343968

Instructions:

  1. Input two integer values. The first one shall accept any integer from 0-9 and the other one shall take a non-zero positive integer.
  2. Using a while loop, count how many of the first integer (0-9) is present in the digits of the second inputted integer and print the result (see sample input and output for example).
  3. Tip #1: You have to use your knowledge from the previous problems in looping through the digits of a number: % 10 to get the rightmost digit, while / 10 to remove the rightmost digit. Make sure to solve the previous problems first.


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
1
Expert's answer
2022-05-24T13:57:55-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS