You are here:

C/sample code

Advertisement


Question
hi..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..

Answer
Hi 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

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

Ability to solve C and Data Structure problems and puzzles with simple and easy to understand logic.

Experience

C, C++, Java, Data Structure, PHP, Web Designing

Organizations
http://www.scodz.com Designation: webmaster

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Past/Present Clients
http://analysingc.50webs.com http://www.funforu.com

©2012 About.com, a part of The New York Times Company. All rights reserved.