इस प्रोग्राम मे मैने function, switch, factorial, और sum का प्रयोग किया है।
Add both header files before run it. Stdio.h and conio.h
int calsum(int x, int y);
int calfact(int x);
int main()
{
int choice, a, b, c, sum, factorial, repeat;
printf("choose 1 for sum\n");
printf("choose 2 for factorial\n");
do
{
printf("enter your choice\n");
scanf("%d", &choice);
switch (choice)
{
case 1:
{
printf("enter two values:\n");
scanf("%d %d", &a, &b);
sum=calsum(a,b);
printf("sum is %d\n", sum);
break;
}
/*created by Shyam Dubey*/
case 2:
{
printf("enter a number:\n");
scanf("%d",&c);
factorial=calfact(c);
printf("factorial of %d is %d\n",c, factorial);
break;
}
default:
printf("choose 1,2 only\n");
}
printf("do you want to repeat 1/0=");
scanf("%d", &repeat);
}while(repeat==1);
getch();
/*shyamitguru*/
}
int calsum(int x, int y)
{
int d;
d=x+y;
return(d);
}
int calfact(int x)
{
int i, fact=1;
for (i=1; i<=x; i++)
fact=fact*i;
return(fact);
}
Add both header files before run it. Stdio.h and conio.h
int calsum(int x, int y);
int calfact(int x);
int main()
{
int choice, a, b, c, sum, factorial, repeat;
printf("choose 1 for sum\n");
printf("choose 2 for factorial\n");
do
{
printf("enter your choice\n");
scanf("%d", &choice);
switch (choice)
{
case 1:
{
printf("enter two values:\n");
scanf("%d %d", &a, &b);
sum=calsum(a,b);
printf("sum is %d\n", sum);
break;
}
/*created by Shyam Dubey*/
case 2:
{
printf("enter a number:\n");
scanf("%d",&c);
factorial=calfact(c);
printf("factorial of %d is %d\n",c, factorial);
break;
}
default:
printf("choose 1,2 only\n");
}
printf("do you want to repeat 1/0=");
scanf("%d", &repeat);
}while(repeat==1);
getch();
/*shyamitguru*/
}
int calsum(int x, int y)
{
int d;
d=x+y;
return(d);
}
int calfact(int x)
{
int i, fact=1;
for (i=1; i<=x; i++)
fact=fact*i;
return(fact);
}
कोई टिप्पणी नहीं:
एक टिप्पणी भेजें