Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Print on screen the output of adding, subtracting, multiplying and dividing of two numbers which will be entered by the user


C# Sharp Basic: Exercise-7 with Solution

Write a C# Sharp program to print on screen the output of adding, subtracting, multiplying and dividing of two numbers which will be entered by the user.

C# sharp Exercises: Print on screen the output of adding, subtracting, multiplying and dividing of two numbers which will be entered by the user

Sample Solution:

C# Sharp Code:

using System;
public class Exercise7
{
    public static void Main()
    {
        Console.Write("Enter a number: ");
        int num1= Convert.ToInt32(Console.ReadLine());
 
        Console.Write("Enter another number: ");
        int num2= Convert.ToInt32(Console.ReadLine());
   
        Console.WriteLine("{0} + {1} = {2}", num1, num2, num1+num2);
        Console.WriteLine("{0} - {1} = {2}", num1, num2, num1-num2);
        Console.WriteLine("{0} x {1} = {2}", num1, num2, num1*num2);
        Console.WriteLine("{0} / {1} = {2}", num1, num2, num1/num2);
        Console.WriteLine("{0} mod {1} = {2}", num1, num2, num1%num2);
   }
}

Sample Output:

Enter a number: 10                                                                                            
Enter another number: 2                                                                                       
10 + 2 = 12                                                                                                   
10 - 2 = 8                                                                                                    
10 x 2 = 20                                                                                                   
10 / 2 = 5                                                                                                    
10 mod 2 = 0 

Flowchart:

Flowchart: C# Sharp Exercises - Print on screen the output of adding, subtracting, multiplying and dividing of two numbers which will be entered by the user

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to print the output of multiplication of three numbers which will be entered by the user.
Next: Write a C# Sharp program that takes a number as input and print its multiplication table.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.