Friday, January 2, 2015

Product of 2 Numbers in c pgm



Find Product of 2 Numbers without using Recursion

#include 
#include 
int product(int, int);
 
int main()
{
    int a, b, result;
    clrscr();
    printf("Enter two numbers to find their product: ");
    scanf("%d%d", &a, &b);
    result = product(a, b);
    printf("Product of %d and %d is %d\n", a, b, result);
    return 0;
}
 
int product(int a, int b)
{
    int temp = 0;
 
    while (b != 0)
    {
        temp += a;
        b--;
    }
    return temp;
}

Output
 
Enter two numbers to find their product:  89  458
Product of 89 and 458 is 40762

No comments:

Post a Comment