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
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;
}
Comments
Leave a comment