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# program to subtract two floating point number

C# program to subtract two floating point number

Posted on May 20, 2022

Table of Contents

  • C# program to subtract two floating point number
    • Code to subtraction of two numbers in C#
      • Subtraction of two floating-point numbers
      • Subtraction of two floating-point numbers – Entered by user

C# program to subtract two floating point number

In this article, we will discuss the concept of C# program to subtract two floating point number

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

Code to subtraction of two numbers in C#

Subtraction of two floating-point numbers

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

Program 1

//Calculate difference of two floating point numbers 
using System; 
public class SubOfFloatNum { 
    public static void Main(string[] args) { 
        float num1=85.8f; 
        float num2=56.9f;//declare and initialize variables
        Console.Write("The difference of two floats: "+num1+"+"+num2+"="); 
        float subTot=num1-num2;//Calculate subtraction of two numbers
        Console.WriteLine(subTot);//display result 
        } }

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

The difference of two floats: 85.8-56.9=28.9

 

Subtraction of two floating-point numbers – Entered by user

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

Program 2

//Calculate sum of two floating point numbers 
using System; 
public class SumOfFloatNum { //class declaration
    public static void Main(string[] args) {
        Console.WriteLine ("Enter float number to fNo");
        //ask input from user for fNo 
        float fNo=float.Parse(Console.ReadLine());
        //Reading input value by user
        Console.WriteLine ("Enter second float number to lNo");//ask input from user for lNo 
        float lNo=float.Parse(Console.ReadLine());
        //Reading input value by user to lNo 
        Console.Write("The difference of two floats: "+fNo+"-"+lNo+"="); 
        float result=fNo-lNo;//calculate sum 
        Console.WriteLine(result); 
        //display result on the screen }
    }
}

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

Enter float number to fNo
120
Enter second float number to lNo
55
The difference of two floats: 120-55=65

 

In this code, the user asked to enter two floating-point numbers and the given numbers are stored in variables fNo and lNo respectively.

Then these two numbers are subtracted using the minus(-) operator and the result is stored in the result variable.

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

Suggested post

Sum of two integers in C#

Sum of two integers using function in C#

Sum of two floating point numbers in C#

 

Subtract two number in Java language

Subtract two number in C language

Subtract two number in C++ language

Subtract two number in Python language

 

Addition of two numberĀ  in Java language

Addition of two number in C language

Addition of two numberĀ  in C++ language

Addition of two number in Python language

 

 

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