C/sample code
Expert: Joydeep Bhattacharya - 12/6/2007
Questionhi..thank you for the help.but what i need is a program in which on the main menu,you'll choose from factorial and fibonacci.then it will perform what ever option you choose as you enter the number.i was told to use functions for factorial and fibonacci.that when you enter a number..it will show the factorial series and the product for factorial and the fibonacci series for fibonacci.hope you can help me as soon as possible.the submission is extended up to tom morning.thank you very much..you're so helpful.good day..
AnswerHi Dimples
here is the entire program for you
#include<conio.h>
#include<stdio.h>
void fact(int no)
{
int i, fact = 1;
if(no>0)
{
printf("1");
for(i = 2 ; i<=no ; i++)
{
printf(" X %d",i);
fact = fact * i;
}
printf(" = %d",fact);
}
else
printf("Error !");
getch();
}
void fib(int no)
{
int a=0,b=1,c = 1,i;
if(no>0)
{
for(i=0;i<no;i++)
{
printf("%d", c);
c = a + b;
a = b;
b = c;
}
}
else
printf("Error !");
getch();
}
void main()
{
int ch, no;
do {
clrscr();
printf("Menu");
printf("\n Press 1 for Factorial");
printf("\n Press 2 for Fibonacci");
printf("\n Press 0 to Exit");
printf("\n Enter your choice: ");
scanf("%d",&ch);
if(ch == 1 || ch == 2)
{
printf("Enter a no: ");
scanf("%d",&no);
printf("\n\n\n\n");
if(ch==1)
fact(no);
else
fib(no);
}
}while(ch!=0);
}
regards
Joydeep Bhattacharya
http://www.scodz.com