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
Sum of two floating point numbers using function in c#

Sum of two floating point numbers in C#

Posted on May 15, 2022May 15, 2022

Table of Contents

  • Sum of two floating point numbers in C#
    • Code to sum of two floating point numbers in C#
      • Add two floating -point numbers in C#
      • Add two floating -point numbers in C# – entered by user
    • Related

Sum of two floating point numbers in C#

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

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

Code to sum of two floating point numbers in C#

Add two floating -point numbers in C#

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

Program 1

//Calculate sum of two floating point numbers 
using System;

public class SumOfFloatNum
{
    public static void Main(string[] args)
    {
        float num1=45.8f;
         float num2=56.9f;//declare and initialize variables
         
         Console.Write("The total of two floats: "+num1+"+"+num2+"=");
         float result=num1+num2;//Calculate addition of two numbers
         Console.WriteLine(result);//display result
    }
}

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

The total of two floats: 45.8+56.9=102.7

 

Add two floating -point numbers in C# – entered by user

In this code, we are going to learn how to write a program to add two numbers (entered by user) in C# programming language

Program 2

//Calculate sum of two floating point numbers 
using System;

public class SumOfFloatNum
{
    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());//input value by user to fNo
        Console.WriteLine ("Enter second float number to lNo");//ask input from user for lNo
         float lNo=float.Parse(Console.ReadLine());//input value by user to lNo
         
         Console.Write("The total 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
76.897
Enter second float number to lNo
45.984
The total of two floats: 76.897+45.984=122.881

 

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 added using the plus(+) operator and the result is stored in the result variable.

Finally the display statement is used to print the addition of these floating-point numbers.

 

Suggested for you

Sum of two integers in C#

Sum of two integers using function in C#

 

Write a program to sum of prime numbers 1 to n in Java language

Write a program to sum of prime numbers 1 to n in C language

Write a program to sum of prime numbers 1 to n in C++ language

Write a program to sum of prime numbers 1 to n in Python  language

 

Write a program to sum of natural numbers 1 to n in Java language

Write a program to sum of prime numbers 1 to n in C language

Write a program to sum of prime numbers 1 to n in C++ language

Write a program to sum of prime numbers 1 to n 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