In: Computer Science
Directions: Convert the following problems below to c++ equivalent code
Problem 3:
3. Add 82 to the number.
4. Remove the hundreds place from your number
5. Add 1 to the number.
6. Subtract this
from your original number (stored in step 2).
7. Output the result obtained
Problem 4:
1. Select two, single digit, numbers, the first being in the range 2 to 6 and the second being in the range 1 to 9.
2. Multiply the first number by five.
3. Add three to that number.
4. Double the number.
5. Add the second number to your previous step.
6. Subtract 6 from the new total and:
The tens place should be the first number given and the ones place should be the second.
#include <iostream> using namespace std; int main() { int num; // read number cout << "Enter a two digit number from 31 to 99: "; cin >> num; // store copy int copy = num; // perform operations num = num + 82; num = num % 100; num = num + 1; num = copy - num; // display result cout << "Result: " << num; }
#include <iostream> using namespace std; int main() { int n1, n2; // reading user inputs cout << "Enter a single digit number between 2 to 6: "; cin >> n1; cout << "Enter another single digit number between 1 to 9: "; cin >> n2; // storing copy of first number int copy_n1 = n1; // perform the operations on copy_n1 copy_n1 = n1 * 5; copy_n1 = copy_n1 + 3; copy_n1 = 2 * copy_n1; copy_n1 = copy_n1 + n2; copy_n1 = copy_n1 - 6; // calculate the ones place and store in variable int ones = copy_n1 % 10; copy_n1 = copy_n1 / 10; // calculate the tens place and store in variable int tens = copy_n1 % 10; // display the results cout << "First digit entered is '" << n1 << "' and tens place is also '" << tens << "'" << endl; cout << "Second digit entered is '" << n2 << "' and ones place is also '" << "'" << ones; }
FOR ANY MODIFICATIONS PLEASE LET US KNOW THROUGH
COMMENTS.
FOR HELP PLEASE COMMENT.
THANK YOU.