In this tutorial, we will discuss the concept of C# program for division of two numbers
In this topic, we are going to learn how to write a program for dividing two numbers (one by one) in C# programming language
In this program, the user declare and initialize two integer variables num1 and num2. Then two numbers are divided using division(/) operator and assigned the result to third (div) variable
Program 1
// Calculate division of two integers in C# program using System; public class Division { public static void Main(string[] args) { int num1=350; //declare and initialize variables int num2=35; int div=num1/num2; //Calculate division of two numbers Console.WriteLine ("The division of two numbers: "+div); } } //display result on the screen
When the above code is executed, it produces the following result
The division of two numbers: 10
In this program, the user is asked to enter two integer values. These two integers are stored in variables n1 and n2 respectively .Then these two numbers are divided using division (/) operator
Then the division of n1 and n2 is evaluated and the result is stored in the div variable. finally the result is displayed on the screen
Program 2
// Calculate division of two integers in C# program using System; public class Div_Of_Two_Num { public static void Main(string[] args) { int n1, n2, div; Console.WriteLine("Find division of two numbers"); Console.Write("Input number to n1: "); n1=Convert.ToInt32(Console.ReadLine()); Console.Write("Input number to n2: "); n2=Convert.ToInt32(Console.ReadLine()); div=n1/n2; Console.WriteLine ("The division of given two integers: "+div); Console.ReadKey(); } }
When the above code is executed, it produces the following result
Find division of two numbers Input number to n1: 125 Input number to n2: 5 The division of given two integers: 25
In the above program, two integer values 125,5 (get input from the user) are stored in n1 and n2. Then n1 and n2 are divided using the division(/) operator for calculate division.
Then the result is stored in another variable div.
Finally, the result is displayed on the screen using display statements in C#
Similar post
Java program to divide two numbers
C program to divide two numbers
C++ program to divide two numbers
Python program to divide two numbers
Java program to divide two floating-point numbers
C program to divide two floating-point numbers
C++ program to divide two floating-point numbers
Python program to divide two floating-point numbers
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…