Answer to Question #307453 in C++ for Ali

Question #307453

 Write a program which takes a number n as input and prints YAYY if the sum of all digits except the rightmost digit is equal to the rightmost digit., otherwise print OOPS


1
Expert's answer
2022-03-08T07:11:52-0500
using namespace std;


/*
	Write a program which takes a number n as input and prints YAYY if the sum of 
	all digits except the rightmost digit is equal to the rightmost digit., otherwise print OOPS
*/




int main()
{
   int x, Sum = 0;
   cout << "\n\tEnter the number : ";   cin >> x;
   while (x != 0) 
   {
      Sum = Sum + x % 10;
      x = x / 10;
   }
   Sum = Sum - (x%10);
   if(Sum == x%10) 	cout<<"\n\ttYAYY";
   else				cout<<"\n\tOOPS";
   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
New on Blog