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 using function in c#

Posted on May 15, 2022

Table of Contents

  • Sum of two floating point numbers using function in c#
    • Code to Add two numbers in C#
      • Add two numbers using function  in C#
      • Add two numbers using function in C# – entered by user

Sum of two floating point numbers using function in c#

In this article, we will discuss the concept of sum of two floating point numbers using function in c#

In this post, we are going to learn how to write a program to add two numbers using user defined function in C# language

Code to Add two numbers in C#

Add two numbers using function  in C#

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

Program 1

//Write a program calculate sum of two numbers using function
using System; 
public class Sum_Two_Float_Num_Fun { 
    public static float sum_Num(float num1, float num2) { //function definition
        float sum; 
        sum=num1+num2; //calculate addition of two numbers
        return sum; //return value
        
    } 
    public static void Main() {
        float n1=68.8f; //declare and initialize float variable
        float n2=53.7f; 
        Console.WriteLine("The sum of {0} and {1} is: {2}: ",n1,n2,sum_Num(n1,n2)); } }//display result

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

The sum of 68.8 and 53.7 is: 122.5:

 

Add two numbers using function 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 using function in C# programming language

Program 2

// Write a program calculate sum of two numbers using function
using System;
public class Sum_Num_Fun { 
    public static float sum_Num(float num1, float num2) 
    { 
        float sum; //declare a variable for total
        sum=num1+num2; //addition of two numbers
        return sum; //return sum to main method
        
    } public static void Main() {
        Console.Write("Enter number for fNum: "); 
        float fNum=Convert.ToSingle(Console.ReadLine()); 
        //input first number 
        Console.Write("Enter number for lNum: "); 
        float lNum=Convert.ToSingle(Console.ReadLine());
        //input second number
        Console.WriteLine("The sum of {0} and {1} is: {2}: ",fNum,lNum,sum_Num(fNum,lNum)); 
        //display total 
    } 
}

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

Enter number for fNum: 123.45
Enter number for lNum: 234.56
The sum of 123.45 and 234.56 is: 358.01:

 

In this code, the user asked to enter two floating-point value and the given values are stored in variables fNum and lNum respectively.

Then these two values are added using the plus(+) operator and the result is stored in the sum variable.

Finally the display statement is used to print the addition of this numbers by calling the function

 

Suggested for you

Sum of two integers in C#

Sum of two integers using function in C#

Sum of two floating point numbers in C#

 

Write a program to add prime numbers 1 to n in Java language

Write a program to add prime numbers 1 to n in C language

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

Write a program to add 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

  • 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