pages

Saturday, 10 April 2021

write a program for which user choose their options which given options in c-programming.

 Q.NO  write a program for which user choose their options which has following options
   1.odd or even  2.greatest of two number  3.triangle are valid or not
 4. +ve or -ve   5. exit    enter your option

#include<stdio.h>

#include<conio.h>

void main()
{
   int a,b,c,option;
   while(1){
         printf(" 1.odd or even");
         printf("\n 2.greatest of two number");
         printf("]n 3.triangle are valid or not");
         printf("\n 4. +ve or -ve");
         printf("\n5. exit");
         printf("\n enter your option");
         scanf("%d",&option);
         switch(option)
         {
         case 1:
                  printf("\n enter a number");
                  scanf("%d",&a);
                  if(a%2==0)
                           printf("\n even number");
                  else
                           printf("odd number");
                  break;
         case 2:
                  printf("\n enter two numbers");
                  scanf("%d %d",&a,&b);
                  if(a>b)
                           printf("\n greatest number is %d",a);
                  else
                           printf("\n greatest number is %d",b);
                  break;
         case 3:
                  printf("\n triangle is valid or not");
                  scanf("%d %d %d",&a,&b,&c);
                  if(a+b+c==180)
                           printf("\n triangle is valid");
                  else
                           printf("\n triangle is not valid");
                  break;
         case 4:
                  printf("\n +ve or -ve");
                  scanf("%d",&a);
                  if(a>0)
                           printf("+ve number");
                  else
                           printf("-ve number");
                  break;
         case 5:
                  exit(0);
                  default:
                  printf("\n wrong option");
                  break;
         }
   }
    getch();
}

No comments:

Post a Comment