Sunday, February 3, 2013

Program to find product of two integers without using * operator


/*
Program to find product of two integers without using * operator
Programmer : Syed Mohammad Ali
*/
#include<stdio.h>
void main()
{
int a,b,prod=0;
printf("Enter two integers\n");
scanf("%d%d",&a,&b);
while(a!=0)
{
prod=prod+b;
a--;
}
printf("Product= %d\n",prod);
}


/*
The basic idea is that we assume that we dont have * operator in the language.
In this case add value of one variable to prod variable second variable number of times. In the example we added b to prod a number of times.
*/

No comments:

Post a Comment