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
    • Related

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

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes