w3resource

C++ Exercises: Divide two numbers and print on the screen

C++ Basic: Exercise-33 with Solution

Write a program in C++ to divide two numbers and print them on the screen.

Visual Presentation:

C++ Exercises: Divide two numbers and print on the screen

Sample Solution:

C++ Code :

#include <iostream> // Including input-output stream header file

using namespace std; // Using the standard namespace

int main() // Start of the main function
{
    cout << "\n\n Divide two numbers and print:\n"; // Outputting a message indicating the purpose of the program
	cout << "----------------------------------\n"; // Outputting a separator line

	int a; // Declaring an integer variable a
	int b; // Declaring an integer variable b
	int resdiv; // Declaring an integer variable resdiv to store the result of division

	a = 30; // Assigning the value 30 to variable a
	b = 10; // Assigning the value 10 to variable b
	resdiv = a / b; // Dividing variable a by variable b and storing the result in resdiv

	cout << " The quotient of " << a << " and " << b << " is : " << resdiv << "\n\n"; // Outputting the quotient of a and b

	return 0; // Returning 0 to indicate successful program execution
}

Sample Output:

Divide two numbers and print:                                         
----------------------------------                                     
 The quotient of 30 and 10 is : 3    

Flowchart:

Flowchart: Divide two numbers and print on the screen

C++ Code Editor:

Previous: Write a program in C++ to check whether a number is positive, negative or zero.
Next: Write a C++ program to display the current date and time.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/cpp-exercises/basic/cpp-basic-exercise-33.php