Write a program to create menu for following operators : a. Arithmetic operator b. Modulo operator c. Relational operator d. Logical operator (switch case)

 




#include<stdio.h>
#include<conio.h>
main()
{
      int a,b,c,choice;
    
      printf("\n 1 arthemetic operater ");
      printf("\n 2 modulo operater ");
      printf("\n 3 relational operater ");
      printf("\n 4 logical operater ");

      printf("\n select an option :");
      scanf("%d",&choice);


      switch (choice)
      {
         case 1 : printf("enter the value of a and b is :");
                  scanf("%d %d",&a,&b);
                  c=a+b;
                  printf("the value of a+b is : %d",c);
                  break;

         case 2 : printf("enter the value of a and b is :");
                  scanf("%d %d",&a,&b);
                  c=a%b;
                  printf("the value of a%b is : %d",c);
                  break;

         case 3 : printf("two no. is a and b is ");
                  scanf("%d%d",&a,&b);
                  if(a>b)       {
                  printf("\n max. = %d",a);
                  printf("\n min. = %d",b);}
                  else  
                  {
                     printf("\n max. = %d",b);
                     printf("\n min. = %d",a); 
                  }
                  break;

         case 4 :   int lower ,upper;
                    char ch;
    
                   printf("enter any character ");
                   scanf(" %c",&ch);

                   lower=(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u');

                   upper=(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U');

                   if ( lower||upper )
                   printf("\nit is a vowel");

                   else
                   printf("\nit is consonent");
                   break;

         default : printf("u choose wrong ");


    }

    
}

output 1 :
1 arthemetic operater 2 modulo operater 3 relational operater 4 logical operater select an option :1 enter the value of a and b is :2 67 the value of a+b is : 69

output 2:
 1 arthemetic operater
 2 modulo operater
 3 relational operater
 4 logical operater
 select an option :2
enter the value of a and b is :2
5
the value of ab is : 2

output 3: 1 arthemetic operater 2 modulo operater 3 relational operater 4 logical operater select an option :3 two no. is a and b is 23 45 max. = 45 min. = 23

output 4:
1 arthemetic operater 2 modulo operater 3 relational operater 4 logical operater select an option :4 enter any character s it is consonent

Comments

Popular Post

Create a base class called shape .Use this class to store two double type values that could be used to compute the area of figures, Derive two specific classes called triangle and rectangle from the base shape .Add to the base class, a member function get_data() to initialise base class data members and another member function display_area() to compute and display the area of figures. Make display_area () as a virtual function and redefine this function in the derived class to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively and display the area. Area of rectangle = x*y Area of triangle = ½*x*y