Table of Contents
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
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
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 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
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.