22. WRITE A C PROGRAM TO EXPLAIN SWITCH PROGRAM, WITHOUT USING BREAK(READ AN INTEGER VALUE BETWEEN 1 TO 5 AND PRINT IT IN WORDS)
/*program to print an integer value in words*/#include<stdio.h>
#include<conio.h>
int main()
{
int a;
clrscr();
printf(“enter a value\n”);
scanf(“%d”,&a);
switch(a)
{
case 1: printf(“the number is one”);
case 2: printf(“the number is two”);
case 3: printf(“the number is three”);
case 4: printf(“the number is four”);
case 5: printf(“the number is five”);
default :(“the number is invalid”);
}
getch();
return 0;
}
output
enter a value 4
the number is four the number is five the number is invalid
23. WRITE A C PROGRAM TO FIND THE AREAS OF DIFFERENT GEOMETRICAL FIGURES USING SWITCH
/*C Program to Find the Areas of Different Geometrical Figuresusing switch*/#include <stdio.h>
#include<conio.h>
void main()
{
int fig_code;
float side,base,length,bredth,height,area,radius;
printf("-------------------------\n");
printf(" 1 --> Circle\n");
printf(" 2 --> Rectangle\n");
printf(" 3 --> Triangle\n");
printf(" 4 --> Square\n");
printf("-------------------------\n");
printf("Enter the Figure code\n");
scanf("%d",&fig_code);
switch(fig_code)
{
case 1: printf("Enter the radius\n");
scanf("%f",&radius);
area=3.142*radius*radius;
printf("Area of a circle=%f\n", area);
/* case to find the area of ciricle */
break;
case 2: printf("Enter the breadth and length\n");
scanf("%f %f",&breadth, &length);
area=breadth *length;
printf("Area of a Rectangle=%f\n", area);
/* case to find area of the rectangle */
break;
case 3: printf("Enter the base and height\n");
scanf("%f %f",&base,&height);
area=0.5 *base*height;
printf("Area of a Triangle=%f\n", area);
/* case to find the area of the triangle */
break;
case 4: printf("Enter the side\n");
scanf("%f",&side);
area=side * side;
printf("Area of a Square=%f\n", area);
/* case to find area of square */
break;
default: printf("Error in figure code\n");
break;
} /* End of switch */
} /* End of main() */
output
OUTPUT of c programming to find the areas of different geometrical figures
==================================================================
Run 1
-------------------------
1 --> Circle
2 --> Rectangle
3 --> Triangle
4 --> Square
-------------------------
Enter the Figure code
2
Enter the breadth and length
2
6
Area of a Rectangle=12.000000
Run 2
-------------------------
1 --> Circle
2 --> Rectangle
3 --> Triangle
4 --> Square
-------------------------
Enter the Figure code
3
Enter the base and height
5
7
Area of a Triangle=17.500000
24. WRITE A C PROGRAM TO CHECK VOWEL OR CONSONANT USING SWITCH CASE
/*C program to check vowel or consonant using switch case*/#include <stdio.h>
int main()
{
char ch;
/*
* Reads an alphabet from user
*/
printf("Enter any character: ");
scanf("%c", &ch);
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': printf("VOWEL");
break;
default: printf("CONSONANT");
}
return 0;
}
output
Enter any alphabet: E
VOWEL
Comments
Post a Comment