Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C# - floating point division using functions

Program to divide two floating point numbers in C#

Posted on June 9, 2022June 9, 2022

Table of Contents

  • Program to divide two floating point numbers in C#
    • Code to division of two floating-point numbers in C#
      • Division of two floating-point  numbers in C#
      • Division of two floating-point numbers in C# – Entered by user
      • Division of two floating-point numbers in C# – using function

Program to divide two floating point numbers in C#

In this article, we will discuss the concept of Program to divide two floating point numbers in C#

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

Code to division of two floating-point numbers in C#

Division of two floating-point  numbers in C#

In this code, we are going to learn how to write a program to division of two floating-point numbers using initialized variables in C# programming language

Program 1

// Calculate division of two floating-point numbers in C# program
using System; 
public class Float_Division{ 
    public static void Main(string[] args) { 
    float firstNum=65.34f;//declare and initialize variables for firstNum
    float lastNum=9.9f; //declare and initialize variables for lastNum
    float divResult=firstNum/lastNum; //Calculate division of two numbers 
        //assign the result to div variable
        Console.WriteLine ("The division of given two floating point numbers: "+divResult); } } //display result on the screen

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

The division of given two floating point numbers: 6.6

 

Division of two floating-point numbers in C# – Entered by user

In this example, the user is asked to enter two floating-point numbers. Then the division of the those two numbers is calculated and displayed on the screen in C#

Program 2

// Calculate division of two floating-point numbers in C# program
using System; 
public class Div_Of_Two_Num { 
    public static void Main(string[] args) { 
        float num_First, num_Last, division; //declare floating point variables
    Console.WriteLine("Find division of two floating point numbers");
    Console.Write("Input first number: "); 
    //Ask input from the user
    num_First=Convert.ToSingle(Console.ReadLine()); 
    //Reading the input
    Console.Write("Input last number "); 
     //Ask input from the user
    num_Last=Convert.ToSingle(Console.ReadLine()); 
        //Reading the input
    division=num_First/num_Last;//Calculate division of given two numbers
Console.WriteLine ("The division of given two floating point numbers: "+division); 
Console.ReadKey(); } }

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

Find division of two floating point numbers
Input first number: 76.63
Input last number 9.7
The division of given two floating point numbers: 7.9

 

In this code, the user asked to enter two floating-point values and the given values are stored in variables num_First and   num_Last respectively.

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

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

 

Division of two floating-point numbers in C# – using function

In this example, the user is asked to enter two floating-point numbers. Then the division of the those two floating-point values  is calculated and displayed on the screen using user-defined function in C#

// Write a program calculate divisionion of two numbers using function 
using System; 
public class Division_Two_Num_Fun { 
    public static float div_Num(float num1, float num2) { 
        float divResult; //declare float variable 
        divResult=num1/num2; //calculate division of the given numbers 
        return divResult;//return value to main method 
        } 
        public static void Main() { Console.Write("Enter number for fNum: "); //Ask input from user 
        float fNum=Convert.ToSingle(Console.ReadLine()); //Reading the input 
        Console.Write("Enter number for lNum: "); //Ask input from user 
        float lNum=Convert.ToSingle(Console.ReadLine()); //Reading the input 
        Console.WriteLine("The division of {0} and {1} is: {2}: ",fNum,lNum,div_Num(fNum,lNum)); } } //display result on the screen

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

Enter number for fNum: 2.42
Enter number for lNum: 1.1
The division of 2.42 and 1.1 is: 2.2:

 

 

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 

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes