divide two floating point numbers
Table of Contents
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
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
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
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
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.