Write a program to accept a two digit number add the sum of its digits to the product of its digits if the value is equal to the number input, output the message, special2 digit num otherwise,output the message not a special two digit num
Answers
Answered by
2
That sounds interesting! Let me try:
I'm making the program in C++ since a language is not specified...
I'm using the fact that if you divide a two digit number by 10, the remainder will give you it's units place and the quotient will give you its tens place.
I'm attaching the file as well as pasting my code here:
#include <iostream>
using namespace std;
int main()
{
int num;
cin >> num;
int units = num % 10; // % is the mod operator
int tens = num / 10;
if (((units + tens) + (units * tens)) == num)
{
cout << "special 2 digit num" << endl;
}
else {
cout << "not a special two digit num" << endl;
} return 0;
}
I hope that helps...
I'm making the program in C++ since a language is not specified...
I'm using the fact that if you divide a two digit number by 10, the remainder will give you it's units place and the quotient will give you its tens place.
I'm attaching the file as well as pasting my code here:
#include <iostream>
using namespace std;
int main()
{
int num;
cin >> num;
int units = num % 10; // % is the mod operator
int tens = num / 10;
if (((units + tens) + (units * tens)) == num)
{
cout << "special 2 digit num" << endl;
}
else {
cout << "not a special two digit num" << endl;
} return 0;
}
I hope that helps...
Attachments:
Similar questions
Please click on that image from a computer and it will download the cpp file for you...