Table of Contents
In this article, we will discuss the concept of C# program to multiply given two numbers
In this post, we are going to learn how to write a program to multiply two numbers in C# language
In this code, we are going to learn how to write a program to multiply two numbers using initialized variables in C# programming language
Program 1
// Calculate multiplication of two integers in C# program using System; public class Multiplication { //Class declaration public static void Main(string[] args) { //main method int num1=15; //declare and initailize variable for num1 int num2=20; //declare and initailize variable for num2 int mul=num1*num2; //Calculate multiplication of two numbers Console.WriteLine ("The multiplication of two numbers: "+mul); } } //display output on the screen
When the above code is executed, it produces the following result
The multiplication of two numbers: 300
In this example, the user is asked to enter two integer numbers. Then the multiplication of the these two integers is calculated and displayed on the screen in C#
Program 2
// Calculate multiplication of two integers in C# program using System; public class Mul_Of_Two_Num { public static void Main(string[] args) { int n1, n2, mul; //declare variables Console.WriteLine("Find multiplication of two numbers: "); Console.Write("Input number to n1: "); //Ask input from the user for n1 n1=Convert.ToInt32(Console.ReadLine()); //Reading the value for n1 Console.Write("Input number to n2: "); //Ask input from the user for n2 n2=Convert.ToInt32(Console.ReadLine()); //Reading the value for n2 mul=n1*n2; //calculate multiplication Console.WriteLine ("The multiplication of given two integers: "+mul); //display result on the screen Console.ReadKey(); } }
When the above code is executed, it produces the following result
Find multiplication of two numbers: Input number to n1: 25 Input number to n2: 30 The multiplication of given two integers: 750
In this code, the user asked to enter two integers and the given integers are stored in variables n1 and n2 respectively.
Then those two numbers are multiplied using the multiplication(*) operator and the result is stored in the mul variable.
Finally the display statement is used to print the multiplication of numbers
In this example, the user is asked to enter two integer numbers. Then the multiplication of the these two integers is calculated and displayed on the screen using user-defined function in C#
Program 3
// Write a program calculate product of two numbers using function using System; public class product_Two_Num_Fun { //class definition public static int pro_Num(int num1, int num2) { //user-defined function definition int product; //declare integer variable product=num1*num2; //calculate multiplication return product; //return value to main method } public static void Main() { //main method Console.Write("Enter number for n1: "); int n1=Convert.ToInt32(Console.ReadLine()); //get int input from the user for n1 Console.Write("Enter number for n2: "); int n2=Convert.ToInt32(Console.ReadLine()); //get int input from the user for n2 Console.WriteLine("The multiplication of {0} and {1} is: {2}: ",n1,n2,pro_Num(n1,n2)); } } //display result on the screen
When the above code is executed, it produces the following result
Enter number for n1: 15 Enter number for n2: 12 The multiplication of 15 and 12 is: 180:
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 program to multiply two floating-point numbers
C++ program to multiply two floating-point numbers
C program to multiply two floating-point numbers
Python program to multiply two floating-point numbers
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.