Users Online

· Guests Online: 41

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C Program to find Product of 2 Numbers using Recursion

This C program using recursion, finds the product of 2 numbers without using the multiplication operator.
Here is the source code of the C program to display a linked list in reverse. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C Program to find Product of 2 Numbers using Recursion
*/
#include <stdio.h>

int product(int, int);

int main()
{
int a, b, result;

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)
{
if (a < b)
{
return product(b, a);
}
else if (b != 0)
{
return (a + product(a, b - 1));
}
else
{
return 0;
}
}

$ cc pgm20.c
$ a.out
Enter two numbers to find their product: 176 340
Product of 176 and 340 is 59840

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.68 seconds
10,273,035 unique visits