C LAB‎ > ‎(Sem2) Data Structures‎ > ‎

Q1. WAP a menu driven program to find... (6 different tasks)

posted Jan 5, 2011, 9:05 AM by Neil Mathew   [ updated Jan 5, 2011, 10:27 AM ]
SOURCE CODE:

 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 ``` ```#include   int fibo(int n) //recursive function, returns nth element of series { if(n==1)       //1st term return 0; else if(n==2)  //2nd term return 1;   return (fibo(n-1)+fibo(n-2)); }   int fact(int n) //recursive function, returning fact { int f;   if(n>0) { f=n*fact(n-1); return f; } else return 1; }   int main() {   int n,i; //to avoid redeclaration and its consequent error int ch=6; //ch is choice   int digit, num, rev=0, A=0; //for palindrome & angstrom checking   do { printf("\n\n MENU "); printf("\n 1. Fibonacci Series "); printf("\n 2. Factorial of number "); printf("\n 3. Multiplication table "); printf("\n 4. Check whether number is Palindrome "); printf("\n 5. Check whether number is Angstrom "); printf("\n 6. EXIT "); printf("\n Enter your choice: "); scanf("%d",&ch); printf("\n");   switch(ch) { case 1:   printf(" Enter the no of elements of fibonacci series to show:"); scanf("%d",&n);   printf("\n Fibonacci: \n"); for(i=1; i<=n; i++) printf(" %d ", fibo(i) );   printf("\n"); break;   case 2:   printf(" Enter the number to find factorial of: "); scanf("%d", &n);   printf("\n Factorial is: %d", fact(n)); break;   case 3:   printf(" Enter the number of whose multiplication table "); printf("is to be made (till 12) :");``````scanf("%d",&n);   printf(" Table: "); for(i=1; i<=12; i++) printf("\n %dx%d=%d ",n,i,(n*i));   break;   case 4:   printf(" Enter number to check whether palindrome: "); scanf("%d",&n);   num=n;   do { digit=num%10; rev=(rev*10)+digit; num/=10; } while(num>0);   if(rev==n) printf("\n Number is Palindrome. "); else printf("\n Number is not Palindrome. ");   break;   case 5:   printf(" Enter number to check whether Angstrom: "); scanf("%d",&n);   num=n;   do { digit=num%10; A+=digit*digit*digit; num/=10; } while(num>0);   if(A==n) printf("\n Number is Angstrom. "); else printf("\n Number is not Angstrom. ");   break;     case 6: printf(" Exiting... "); break;   default: printf("INVALID CHOICE"); }   } while(ch!=6);   return 0; }  ```

OUTPUT:

``` MENU
1. Fibonacci Series
2. Factorial of number
3. Multiplication table
4. Check whether number is Palindrome
5. Check whether number is Angstrom
6. EXIT
Enter your choice: 1

Enter the no of elements of fibonacci series to show:8

Fibonacci:
0  1  1  2  3  5  8  13

1. Fibonacci Series
2. Factorial of number
3. Multiplication table
4. Check whether number is Palindrome
5. Check whether number is Angstrom
6. EXIT
Enter your choice: 2

Enter the number to find factorial of: 4

Factorial is: 24

1. Fibonacci Series
2. Factorial of number
3. Multiplication table
4. Check whether number is Palindrome
5. Check whether number is Angstrom
6. EXIT
Enter your choice: 3

Enter the number of whose multiplication table is to be made (till 12): 17
Table:
17x1=17
17x2=34
17x3=51
17x4=68
17x5=85
17x6=102
17x7=119
17x8=136
17x9=153
17x10=170
17x11=187
17x12=204

1. Fibonacci Series
2. Factorial of number
3. Multiplication table
4. Check whether number is Palindrome
5. Check whether number is Angstrom
6. EXIT
Enter your choice: 4

Enter number to check whether palindrome: 121

Number is Palindrome.

1. Fibonacci Series
2. Factorial of number
3. Multiplication table
4. Check whether number is Palindrome
5. Check whether number is Angstrom
6. EXIT
Enter your choice: 5

Enter number to check whether Angstrom: 371

Number is Angstrom.