Calculations

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

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 program, we can see step by step procedure for completion of the program.

  • Function declaration or prototype
  • essential variable declaration
  • taking input value from the user for find product
  • Define the function with parameter
  • Calling the function wit argument
  • Display result on the screen

 

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

 

Suggested for you

Function in C++ language

Operator in C++ language

Data type in C++ language

Python program to multiply two numbers
Java Program to calculate average of an Array
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.

View Comments

  • #include
    using namespace std;
    int main()
    {
    int a=10,b=20;
    int multi(int,int);
    cout<<"before function calling";
    multi(a,b);
    return 0;

    }
    void multi(int x , int y)
    {
    int z;
    z=x*y;
    cout<<"value of z is"<<z<<endl;

    }

Recent Posts

PHP Star Triangle pattern program

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

1 month ago

PHP Full Pyramid pattern program

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

1 month ago

5 methods to add two numbers in Java

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

2 months ago

Python Full Pyramid star pattern program

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

5 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…

9 months 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,…

10 months ago