Question

Directions: Convert the following problems below to c++ equivalent code Problem 6: Get a random number...

Directions: Convert the following problems below to c++ equivalent code

Problem 6:

  1. Get a random number from the user
  2. Remember the original number
  3. Add 3 to the number
  4. Double the number
  5. and then multiply by
  6. Knock off the last digit (remove the 1’s place)
  7. Finally remove the original number
  8. What is the result?

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?

Homework Answers

Answer #1

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);

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Problem: Certain mathematical problems involve manipulation of the digits within a whole number. One such problem...
Problem: Certain mathematical problems involve manipulation of the digits within a whole number. One such problem requires that the digits be re-arranged.In this project, we will reverse the order of the digits in a number. Assignment: Design, develop, and test an Object-Oriented C++program that reads a whole number from the user, removes the sign and all leading and trailing zeroes from that number, and then performs the following operations on that number: 1) reverses the digits, 2) sorts the digits...
Problem: Our Armstrong number Please write code for C language So far we have worked on...
Problem: Our Armstrong number Please write code for C language So far we have worked on obtaining individual digits from 4 digits or 5 digit numbers. Then added them to find the sum of digits in various examples and assignments. However, the process of extracting individual digits is actually can be solved using a loop as you were doing a repetitive task by using mod operation and division operation. Now, we know how loops work and we can remove the...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
Base Conversion One algorithm for converting a base 10 number to another base b involves repeatedly...
Base Conversion One algorithm for converting a base 10 number to another base b involves repeatedly dividing by b. Each time a division is performed the remainder and quotient are saved. At each step, the dividend is the quotient from the preceding step; the divisor is always b. The algorithm stops when the quotient is 0. The number in the new base is the sequence of remainders in reverse order (the last one computed goes first; the first one goes...
Provide a complete solution to the following problem using the C++ language in a SINGLE file...
Provide a complete solution to the following problem using the C++ language in a SINGLE file with a .cpp file extension. READ THE ENTIRE QUESTION (AND THE EXAMPLE) CAREFULLY BEFORE DEVELOPING YOUR SOLUTION! Design the code for a class called Pi, which will be used to encapsulate the value of pi stored as a string. (example ONLY) "3.141592654" | |_ _ _ _| whole number portion_| |_ _ _ _ _fractional portion (9 digits) The Pi class has the following...
Problem a (PA5a.java) Write a program that deals with inflation, which is essentially the rising cost...
Problem a (PA5a.java) Write a program that deals with inflation, which is essentially the rising cost of general goods over time. That is, the price of goods, such as a packet of peanuts, goes up as time goes by. So, you will write a program to gauge the expected cost of an item in a specified number of years. The program asks for the cost of the item, the number of years, and the rate of inflation. The output is...