In the Mini project, the 5th module is to find the product of two values without using ‘*’ operator. Rita allotted this function to Pooja.
Help Pooja to write a program to find the product of two values without using ‘*’ operator?
Function specification:
int product(int ,int );
Input format :
Input consists of two integers multiplicand and multiplier.
Output format :
The output consists of an integer which is the product of two inputs.
Refer Sample Input and Output for formatting details.
[ All text in bold corresponds to the input and the rest corresponds to output.]
Sample Input and Output :
Enter the two numbers :
2
3
The product is 6


Program Code:
#include<stdio.h>
#include<math.h>
int product(int num1, int num2)
{
    int ans;
   while(num2 != 0)
{
ans = ans + num1;
num2--;
}
return ans;
}
int main()
{
    int a,b;
    printf("Enter the two numbers :\n");
    scanf("%d%d",&a,&b);
    printf("The product is %d",product(a,b));
    return 0;
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: