Calculations

Program to multiply two numbers using function in C#

Program to multiply two numbers using function in C#

In this tutorial, we will discuss the concept of Program to multiply two numbers using function in C#

In this topic, we are going to learn how to write a program for multiplying two numbers using user defined-function in C# programming language

 

Multiplication of two numbers in C#

Multiplication of two numbers

Multiplication of two numbers using variable

In this program, the user declare and initialize two integer variables num1 and num2. Then two numbers are multiplied using multiplication(*) operator and assigned the result to third (mul) variable

Program 1

//Write a program calculate multiplication of two numbers using function
using System; 
public class Mul_Two_Num_Fun { //class definition
public static int mul_Num(int num1,int num2) { //user defined function with argument 
int mul; 
mul=num1*num2; //Calculate product of given numbers
return mul; 
    
} public static void Main() { 
    int num1=45; //Declare and initialize variable 
    int num2=50; 
    Console.WriteLine("The multiplication of {0} and {1} is: {2}: ",num1,num2,mul_Num(num1,num2)); } }
 //Display result on the screen

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

The multiplication of 45 and 50 is: 2250:

 

Multiplication of two numbers – Entered by user

In this program, the user declare and initialize two integer variables n1 and n2. Then two numbers are multiplied using multiplication(*) operator and assigned the result to third (mulRes) variable

Program 2

// Write a program calculate multiplication of two numbers using function 
using System; public class Mul_Two_Num_Fun { 
    public static int mul_Num(int num1, int num2) {
        //function definition 
    int mulRes; //declare integer variable 
    mulRes=num1*num2; //calculate multiplication
    return mulRes; 
        
    }
    public static void Main() { 
        Console.Write("Enter number for n1: ");
        int n1=Convert.ToInt32(Console.ReadLine()); //get input from the user for n1 
        Console.Write("Enter number for n2: "); 
        int n2=Convert.ToInt32(Console.ReadLine()); //get input from the user for n2
        Console.WriteLine("The multiplication of {0} and {1} is: {2}: ",n1,n2,mul_Num(n1,n2)); } } 
        //display result on the screen

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

Enter number for n1: 12
Enter number for n2: 13
The multiplication of 12 and 13 is: 156:

 

In the above program, two integer values 12,13 (get input from the user) are stored in n1 and n2. Then n1 and n2 are multiplied using the multiplication(*) operator.

Then the result is stored in another variable mulRes.

Finally, the result is displayed on the screen using display statements in C#

 

Similar post

Java program to multiply two numbers

C program to multiply two numbers

C++ program to multiply two numbers

Python program to multiply two numbers

 

Java code to multiply two floating-point numbers

C code to multiply two floating-point numbers

C++ code to multiply two floating-point numbers

Python code to multiply two floating-point numbers

 

Java code to multiply two numbers using methods

C code to multiply two numbers using function

C++ code to multiply two numbers using function

Python code to multiply two numbers function

How to multiply two floating point numbers in C#
C# program: multiply two floating-point numbers using function
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

6 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

6 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

6 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

9 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

1 year ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

1 year ago