Site icon Codeforcoding

C program to multiply two numbers using function

C program to multiply two numbers using the function

In this tutorial, we will discuss the C program to multiply two  numbers using the function

In this topic, we will learn a simple concept of how to multiply two numbers using the function in the C programming language

already we learned the same concept using the operator.

if you known click here C program to multiply two numbers

In this program, we can see step by step procedure for completion of the program.

  1. Function declaration or prototype
  2. essential variable declaration
  3. taking input value from the user for find product
  4. Define the function with parametert
  5. Call the function with argument
  6. Display result on the screen

 

multiply two integer numbers – takes input from user

In this tutorial, you will learn how to multiply two integer numbers in Java by taking input from the user. This is a basic program that’s perfect for beginners to understand how user input and arithmetic operations work in Java. We’ll use the Scanner class to get input from the user and then perform the multiplication

Program 1

#include <stdio.h>
#include <stdlib.h>
int multiplyNum(int , int);//function declaration or prototype
int main()
{
int num1,num2,product;//variable declaration
printf("Enter the two number ");
scanf("%d %d",&num1,&num2);//taking two number as input from user
product=multiplyNum(num1,num2);//calling the function
//The product value (returned by the function) is stored in product variable.
printf("The product of these numbers :%d",product);
//display the product value
getch();
return 0;
}
int multiplyNum(int a, int b)//defining function based in declaration
{
int result=a*b;//find product of two numbers
//and result stored in result variable
return result;//returning result
}

When the above code is compiled and executed, it produces the following results

Enter the two numbers 12
23
The product of these numbers :276

 

multiply two floating point numbers – takes input from user

In this tutorial, you will learn how to multiply two floating point numbers in Java by taking input from the user. This program demonstrates how to handle decimal numbers using the float or double data type and how to use the Scanner class to read user input. It’s a simple example to help you understand basic arithmetic operations with floating point numbers in Java.

In this program, we can see step by step procedure for completion of the program.

 

Program  2

#include <stdio.h>
#include <stdlib.h>
float multiplyNum(float, float);
int main()
{
    float num1,num2,product;
    //variable declaration
    printf ("Enter both numbers\n");
    scanf("%f %f" ,&num1,&num2);//Taking numbers as input
    product=multiplyNum(num1,num2);//calling the function
    //The product value (returned by the function) is stored in product variable.
    printf("The product of these numbers :%.2f",product);
    //display the product value
    getch();
    return 0;
    }
    float multiplyNum(float a, float b){
    //defining function based in declaration
    float result=a*b;//find product of two numbers
    //and result stored in result variable return result;
    return result;//returning result }
}

When the above code is compiled and executed, it produces the following results

Enter both numbers
12.34
23.45
The product of these numbers:289.37

Similar post

C++ program to multiply two numbers using function

Java program to multiply two numbers using method

Python program to multiply two numbers using function

C# program to multiply two numbers using function

PHP program to multiply two numbers using function

 

 

C program to multiply two numbers 

C++ program to multiply two numbers

Java program to multiply two numbers 

Python program to multiply two numbers 

C# program to multiply two numbers 

PHP program to multiply two numbers 

JavaScript program to multiply two numbers 

 

Calculate the total of array elements in Java

Calculate the total of array elements in C

Calculate the total of array elements in C++

Java program to calculate sum of array elements

C program to calculate sum of array elements

Java Program to calculate average of array

C Program to calculate average of array

Java Program to calculate average of odd and even numbers in an array

Java Program to calculate average of odd and even numbers

C Program to calculate average of odd and even numbers in an array

C Program to calculate average of odd and even numbers

C++ Program to calculate average of odd and even numbers in an array

C++ Program to calculate average of odd and even numbers

 

 

 

Suggested for you

Operator in C language

for loop in C language

Single dimensional array in C language

Data type and variable in C language

Operator in C++ language

For loop in C++ language

Single dimensional array in C++ language

The data type in C++ language

Operator in Java

for loop in Java

Single dimension array in Java

 

 

Python program to multiply two numbers
Java Program to calculate average of an Array
Exit mobile version