Answer to Question #279076 in C++ for wewew

Question #279076
  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
Expert's answer
2021-12-13T08:34:35-0500
#include<iostream>

using namespace std;

int main()
{
	int first, second;
	int count=0;
	do
	{
		cout<<"Please, enter an integer from 0-9: ";
		cin>>first;
	}while(first<0||first>9);
	do
	{
		cout<<"Please, enter an integer : ";
		cin>>second;
	}while(second<0);
	int tmpsec=second;
	while(tmpsec>=0)
	{
		
		int temp = tmpsec%10;
		if(temp==first)count++;
		tmpsec=tmpsec/10;
		if(tmpsec==0)break;
	}
	cout<<first<<" presents in "<<second<<" "<<count<<" times";
}

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
New on Blog