C Program To Find Factorial of given numbers,+ve numbers – Menu Driven Program

#include<stdio.h>
int fact(int);
int mul(int,int);
int add(int,int);
int main()
{
int num1,num2,cho;
char c1;
while(1)
{
printf("\n*******SELECT ANY ONE OF THE FOLLOWING OPTION*****\n");
printf("\n1. factorial of a given +ve number\n2. product of given two numbers\n3. sum of given two numbers\n");
scanf("%d",&cho);
switch(cho)
{
case 1:
printf("\nEnter a +ve number\n");
scanf("%d",&num1);
printf("factorial of given number is = %d",fact(num1));
break;
case 2:
printf("\nEnter two +ve number\n");
scanf("%d%d",&num1,&num2);
printf("product of given 2 numbers is = %d",mul(num1,num2));
break;
case 3:
printf("\nEnter two +ve number\n");
scanf("%d%d",&num1,&num2);
printf("sum of given 2 numbers is = %d",add(num1,num2));
break;
default:
printf("*******ENTERED OPTION IS WRONG OPTION******");
}
printf("\nDO YOU WANT CONTINUE y/n\n");
fflush(stdin);
scanf("%c",&c1);
if(c1 == 'y' || c1 =='Y')
continue;
else
break;
}
return(0);
}
int fact(int num1)
{
if(num1 == 0)
return 1;
else
return num1 * fact(num1-1);
}
int add(int num1,int num2)
{
if(num2 == 1)
return num1+1;
else
return add(num1+1,num2-1);
}
int mul(int num1,int num2)
{
if(num2 == 1)
return num1;
else
return num1 + mul(num1,num2-1);
}


Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors and Social Networking. Feel Free to let me know any of your concerns about hacking or let me know if you need any more methods on hacking anything. Enjoy Learning

No comments:

Post a Comment