Arithmetic Caculation

C# program to find division of two numbers using functions

C# program to find division of two numbers using functions

In this article, we will discuss the concept of c# program to find division of two numbers using functions

In this post, we are going to learn how to write a program to division of two numbers using function in C# language

Code to division of two numbers in C#

Division of two numbers using function in C#

In this code, we are going to learn how to write a program to division of two numbers using function in C# programming language

Program 1

//Write a program find division of two numbers using function
using System; 
public class Div_Two_Num_Fun { //class definition 
public static int div_Num(int num1,int num2) { //user defined function 
int div; //declare integer variable to assign result
div=num1/num2; //Calculate division of given numbers 
return div; //return result to main method
} 
public static void Main() { 
    int n1=600; //Declare and initialize int variable n1
    int n2=50; //Declare and initialize int variable n2
    Console.WriteLine("The division of {0} and {1} is: {2}: ",n1,n2,div_Num(n1,n2)); } } //Display result on the screen

When  the above code  is executed, it produces the following result

The division of 600 and 50 is: 12:

 

Division of two numbers using function in C# – Entered by user

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 function in C#  language

Program 2

// Write a program find division of two numbers using function 
using System; 
public class DivTwoNumFun { 
    public static int divtwoNum(int num1, int num2) { //function definition with parameter
    int divResult; //declare integer variable for result
    divResult=num1/num2; //calculate division 
    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 screenv

When  the above code  is executed, it produces the following result

Enter first number: 120
Enter last number: 6
The division of 120 and 6 is: 20:

In this code, the user asked to enter two integers and the given integers are stored in variables n1 and n2 respectively.

Then those two numbers are divided using the division(/) operator and the result is stored in the divResult variable.

Finally the display statement is used to print the division of numbers

 

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 

C++ program to find quotient and remainder

Python program to find quotient and remainder 

 

Java program  to print  multiplication table

C program  to print multiplication  table

C++ program  to  print  multiplication  table

Python program  to print  multiplication  table

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.