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;
}
Post A Comment:
0 comments: