Question

In: Computer Science

In C++ Prompt user to enter two integers •Determine whether the first number is divisible by...

In C++

Prompt user to enter two integers

•Determine whether the first number is divisible by the second. If the second number is zero, the program should not do division

•Output the remainder of the two numbers

•Compare the two integers, display the integers in non-decreasing order.

Solutions

Expert Solution

Programming Language C++ Program to determine whether the first number is divisible by the second number, display the remainder of two number and display the integers in non-decreasing order.

#include <iostream>
using namespace std;

int main()
{

//variable declaration
int firstNumber, secondNumber, rem;
cout<<"Enter the first number: ";
cin>>firstNumber;
cout<<"Enter the second number: ";
cin>>secondNumber;
if(secondNumber != 0)
{

//calculate remainder
rem = firstNumber % secondNumber;
if(rem == 0)
cout<<"The first number is divisible by the second number";
else
cout<<"The first number is not divisible by the second number";
cout<<endl<<"The remainder is: "<<rem;
}
if(firstNumber<secondNumber)
cout<<endl<<"Decreasing order is: "<<firstNumber<<" "<<secondNumber;
else

cout<<endl<<"Non-decreasing order is: "<<secondNumber<<" "<<firstNumber;
return 0;
}

INPUT:

Enter the first number: 20                                                                                                      

Enter the second number: 15                                                                                                     

OUTPUT:

The first number is not divisible by the second number                                                                              

The remainder is: 5                                                                                                             

Non-decreasing order is: 15 20


Related Solutions

Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
C++ Prompt the user for the number of guests attending the event. Determine and report the...
C++ Prompt the user for the number of guests attending the event. Determine and report the number of large, medium, and small pizzas you need to order. For every 7 guests, order one large pizza. For every 3 guests left over, order one medium pizza. For every 1 guest left over, order one small pizza. Part 2 - Serving Size Compute and report the total area of pizza (in square inches) you need to purchase. Do not round these values....
Program IN C Prompt the user to enter month number and year. Retain an appropriate response...
Program IN C Prompt the user to enter month number and year. Retain an appropriate response for invalid month numbers, but don’t worry about validity of year. 2.Determine the number of days in the month entered (ignore leap years). 3.Use the answer to step 2 in one FOR-LOOP to ask the user to enter a FAHRENHEIT temperature (integer or floating) for each day of the month utilizing a prompt that includes the DATE. a. Prompt the user to enter the...
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
Assignment in C: prompt the user to enter secret message that is terminated by presding Enter....
Assignment in C: prompt the user to enter secret message that is terminated by presding Enter. You can assume that the the length of this message will be less than 100 characters. You will then parae this message, character by character, converting them to lower case, and find corresponding characters in the words found in the key text word array. Once a character match is found, you will write the index of the word and the index of the character...
Question Write a C program that asks the user to enter two integers x and n....
Question Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. and give me an output please use printf and scanf #include int main(void) {     //Declare required variables             //read two integers x , n from the keyboard                 //compute xn using for loop                     printf("< Your name >\n");...
Write a PowerShell script which will prompt user to enter the number of the day of...
Write a PowerShell script which will prompt user to enter the number of the day of the week (e.g. 1,2,3,4,5,6,7) and return the day of the week. (e.g. Sunday...etc.) (Hint: Sunday is the 1st day of the week).
4. Prompt user to enter a double number from console. Round this number so it will...
4. Prompt user to enter a double number from console. Round this number so it will keep 2 places after the decimal point. Display new number. For example, number 12.3579 will round to 12.36; number 12.4321 will round to 12.43 This is meant to be written in Java 14.0
Create in C++ Prompt the user to enter a 3-letter abbreviation or a day of the...
Create in C++ Prompt the user to enter a 3-letter abbreviation or a day of the week and display the full name of the day of the week. Use an enumerated data type to solve this problem. Enumerate the days of the week in a data type. Start with Monday and end with Friday. Set all of the characters of the user input to lower case. Set an enumerated value based on the user input. Create a function that displays...
Write a C program Your program will prompt the user to enter a value for the...
Write a C program Your program will prompt the user to enter a value for the amount of expenses on the credit card. Retrieve the user input using fgets()/sscanf() and save the input value in a variable. The value should be read as type double. The user may or may not enter cents as part of the input. In other words, expect the user to enter values such as 500, 500.00 and 500.10. The program will then prompt the user...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT