Table of Contents
In this article, we will discuss the concept of CSharp program to divide two numbers
In this post, we are going to learn how to write a program to divide two numbers (one by one) in C# language
In this code, we are going to learn how to write a program to divide two numbers using variable(initialization) in C# programming language
Program 1
// Calculate division of two integers in C# program using System; public class Division { public static void Main(string[] args) { int fNum=35; //declare and initialize variables for fNum int lNum=7; //declare and initialize variables for lNum int div=fNum/lNum; //Calculate division of two numbers //assign the result to div variable 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: 5
In this example, the user is asked to enter two integer numbers. Then the division of the these two integers is calculated and displayed on the screen in C#
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 numOne, numTwo, div; //declare integer variables Console.WriteLine("Find division of two numbers"); Console.Write("Input first number: "); //Ask input from the user numOne=Convert.ToInt32(Console.ReadLine()); //Reading the input Console.Write("Input second number "); //Ask input from the user numTwo=Convert.ToInt32(Console.ReadLine()); //Reading the input div=numOne/numTwo; //Calculate division of given two numbers 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 first number: 1250 Input second number 50 The division of given two integers: 25
In this code, the user asked to enter two integers and the given integers are stored in variables numOne and numTwo respectively.
Then those two numbers are divided using the division(/) operator and the result is stored in the div variable.
Finally the display statement is used to print the division of numbers
In this example, the user is asked to enter two integer numbers. Then the division of the these two integers is calculated and displayed on the screen using user-defined function in C# language
Program 3
// Write a program find division of two numbers using function using System; public class DivTwo_NumFun { public static int divtwoNum(int num1, int num2) { //User defined function definition with parameter int divResult; //declare integer variable for result divResult=num1/num2; //calculate division //assign the result to third variable return divResult; } //return result to main method public static void Main() { Console.Write("Enter first number: "); int n1=Convert.ToInt32(Console.ReadLine()); //get input from the user for n1 Console.Write("Enter last number: "); int n2=Convert.ToInt32(Console.ReadLine()); //get input from the user for n2 Console.WriteLine("The division of {0} and {1} is: {2}: ",n1,n2,divtwoNum(n1,n2)); } } //display result on the screen
When the above code is executed it produces the following resultv
Enter first number: 120 Enter last number: 6 The division of 120 and 6 is: 20:
Suggested post
Java program to divide two number
C program to divide two number
C++ program to divide two number
Python program to divide two number
java program to find quotient and remainder
C program to find quotient and remainder
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.