Directions: Convert the following problems below to c++ equivalent code
Problem 6:
Problem 7:
1: Have the person write down any
three digits number with decreasing digits (432 or 875).
2: Reverse the number you wrote in #1.
3: Subtract the number obtained in #2 from the number you wrote in
#1 (#1 - #2)
4: Reverse the number obtained in #3
5: Add the numbers found in #3 and #4
What is the answer?
6.
CODE
#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
int i = num;
num += 3;
num *= 2;
num /= 10;
num -= i;
cout << num;
}
7.
CODE
#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a 3-digit number: ";
cin >> num;
int i = num, reverse = 0, rem;
while(num != 0)
{
rem = num % 10;
reverse = reverse * 10 + rem;
num /= 10;
}
int diff = i - reverse;
i = diff;
reverse = 0;
while(diff != 0)
{
rem = diff % 10;
reverse = reverse * 10 + diff;
diff /= 10;
}
cout << (i + reverse);
}
Get Answers For Free
Most questions answered within 1 hours.