//program to carry out different operation using switch.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int choice;
int length_rect,breadth_rect;
char string[200];
printf("'we have following menu\n");
printf( "1.to get length of string\n");
printf("2. to get area of rectangle\n");
printf("3 to reverse a string\n");
printf("4 exit");
printf("enter your choice 1 or 2 or 3 or 4\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("we are going to get length of string\n");
printf("enter string\n");
gets(string);
printf("the length=%d",strlen(string));
break;
case 2:
printf("we are going to get area of rectangle\n");
printf("enter its length and breadth\n");
scanf("%d%d",&length_rect,&breadth_rect);
printf("the area=%d",length_rect*breadth_rect);
break;
case 3:
printf("we are going to reverse the string\n");
printf("enter your string\n");
gets(string);
printf("the reverse=%s",strrev(string));
break;
case 4:
printf("we are going to exit\n");
break;
default:
printf("sorry, not a valid input\n");
printf("thank u, terminating....\n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int choice;
int length_rect,breadth_rect;
char string[200];
printf("'we have following menu\n");
printf( "1.to get length of string\n");
printf("2. to get area of rectangle\n");
printf("3 to reverse a string\n");
printf("4 exit");
printf("enter your choice 1 or 2 or 3 or 4\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("we are going to get length of string\n");
printf("enter string\n");
gets(string);
printf("the length=%d",strlen(string));
break;
case 2:
printf("we are going to get area of rectangle\n");
printf("enter its length and breadth\n");
scanf("%d%d",&length_rect,&breadth_rect);
printf("the area=%d",length_rect*breadth_rect);
break;
case 3:
printf("we are going to reverse the string\n");
printf("enter your string\n");
gets(string);
printf("the reverse=%s",strrev(string));
break;
case 4:
printf("we are going to exit\n");
break;
default:
printf("sorry, not a valid input\n");
printf("thank u, terminating....\n");
}
getch();
}