Computer Science, asked by nasreen803, 1 year ago

write a menu driven program using first 10 terms of fibonacci series using switch statement​

Answers

Answered by Ankitgunjan
2

Answer:

drow a block diagram to illustrate basic organisation of a computer system and explain the function of various unit

Answered by ZunayedTIME
1

Answer:

Explanation:

#include <stdio.h>

#include <conio.h>

#include <math.h>

void main()

{

                int t,count,num,s,i,choice,f1=0,f2=1,f3;

                clrscr();

                printf(“\nHow many terms you need ?  “);

                scanf(“%d”,&t);

                printf(“\n*******************************”);

                printf(“\n* 1. Prime numbers            *”);

                printf(“\n* 2. Fibonacci series numbers *”);

                printf (“\n* 3. Exit                     *”);

                printf(“\n*******************************”);

           do

{

                printf(“\n\nEnter choice =>”);

                scanf(“%d”,&choice);

                switch(choice)

{

        case 1:

                     printf(“\n%d Prime numbers are :\n”,t);

                     printf(“%8d”,2); // 2 is the first prime number

                     count=1;

                     num=3;

                     while(count<t)

{

              s=sqrt(num);

                      i=2;

                      while(i<=s)

{

             if(num%i==0)

                 break;

                 i++;

}

                   if(i>s)

{

                 printf(“%8d”,num);

                       count++;

}

   num=num+2;

}

break;

      case 2:

                 printf(“\n%d Fibonacci numbers are :\n”,t);

                      printf(“%8d%8d”,f1,f2); // 0 and 1 are first 2 fibonacci numbers

                 count=3;

           while(count<=t)

{

               f3=f1+f2;

               printf(“%8d”,f3);

               f1=f2;

               f2=f3;

              count++;

}

             break;

         case 3: exit();

         default:

                  printf(“\nChoice is wrong!!!”);

               getch();

}

}

         while(choice<=3);

}

Similar questions