Switch Case

C program to check given alphabate is vowel or not using switch case

#include<stdio.h> #include<conio.h> void main() { char ch; clrscr(); printf(“Enter an alphabate:”); scanf(“%c”,&ch); switch(ch) { case ‘a’: case ‘A’: case ‘e’: case ‘E’: case ‘i’: case ‘I’: case ‘o’: case ‘O’: case ‘u’: case ‘U’: printf(“The alphabate is vowel”); break; default: printf(“The alphabate is not vowel”); } getch(); }

C program to perform arithmetic operations using switch case

#include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int ch; float a,b,res; clrscr(); printf(“Enter two numbers:”); scanf(“%f%f”,&a,&b); printf(“nMenun1.Additionn2.Subtractionn3.Multiplicationn4.Division”); printf(“nEnter your choice:”); scanf(“%d”,&ch); switch(ch) { case 1: res=a+b; break; case 2: res=a-b; break; case 3: res=a*b; break; case 4: res=a/b; break; default: printf(“Wrong choice!!nPress any key…”); getch(); exit(0); } printf(“nResult=%f”,res); getch(); }

C++ program to enter a number and print it into words

#include<iostream.h> #include<conio.h> void once(int a) { switch(a) { case 1: cout<<“One”; break; case 2: cout<<“Two”; break; case 3: cout<<“Three”; break; case 4: cout<<“Four”; break; case 5: cout<<“Five”; break; case 6: cout<<“Six”; break; case 7: cout<<“Seven”; break; case 8: cout<<“Eight”; break; case 9: cout<<“Nine”; break; } } int tens(int a,int b) { int flag=0; switch(a) { …

C++ program to enter a number and print it into words Read More »

C++ program to calculate area of a circle,a rectangle or a triangle depending upon user's choice

#include<iostream.h>#include<conio.h>#include<math.h> void main(){ clrscr(); //to clear the screen float a,b,c,s,r,area; int ch; cout<<“***Menu***n1.Area of circlen2.Area of Rectangle”; cout<<“n3.Area of trianglenEnter your choice:”; cin>>ch; switch(ch) { case 1: { cout<<“nEnter radius of the circle:”; cin>>r; area=3.14*r*r; break; } case 2: { cout<<“nEnter length and breadth:”; cin>>a>>b; area=a*b; break; } case 3: { cout<<“nEnter three sides of …

C++ program to calculate area of a circle,a rectangle or a triangle depending upon user's choice Read More »

C program to input number of week's day(1-7) and translate to its equivalent name of the day of the week

#include<stdio.h>#include<conio.h> void main(){ int ch; clrscr(); //to clear the screen printf(“Enter number of week’s day(1-7):”); scanf(“%d”,&ch); switch(ch) { case 1: printf(“nSunday”); break; case 2: printf(“nMonday”); break; case 3: printf(“nTuesday”); break; case 4: printf(“nWednesday”); break; case 5: printf(“nThursday”); break; case 6: printf(“nFriday”); break; case 7: printf(“nSaturday”); break; } getch(); //to stop the screen}

C++ Program to perform all arithmetic calculation using switch case

#include<iostream.h> #include<conio.h> void main() { clrscr(); float a,b,res; int ch,q; cout<<“Arithmetic Operatios”; cout<<“nn1.Additionn2.Subtractionn3.Multiplicationn4.Divisionn5.Mode”; cout<<“n  Enter your choice:”; cin>>ch; switch(ch) { case 1: { cout<<“nnEnter two variables:”; cin>>a>>b; res=a+b; cout<<“n  Result=”<<res; } break; case 2: { cout<<“nnEnter two variables:”; cin>>a>>b; res=a-b; cout<<“n  Result=”<<res; } break; case 3: { cout<<“nnEnter two variables:”; cin>>a>>b; res=a*b; cout<<“n  Result=”<<res; } …

C++ Program to perform all arithmetic calculation using switch case Read More »

C++ Program for temperature conversion which converts fahrenheit to celcius or celcius to fahrenheit depending upon user's choice

#include<iostream.h>#include<conio.h> void main(){ clrscr(); //to clear the screen float temp,res; int choice; cout<<“Temperature Conversion”<<“nn   1.Fahrenheit to Celcius”; cout<<“n   2.Celcius to FahrenheitnnEnter your choice:”; cin>>choice; switch(choice){ case 1: {     cout<<“nEnter temperature in Fahrenheit:”;     cin>>temp;     res=(temp-32)/1.8;} break; case 2: {     cout<<“nEnter temperature in Celcius:”;     cin>>temp;     res=(temp*1.8)+32;} break; } cout<<“nConverted Temperature=”<<res; getch(); …

C++ Program for temperature conversion which converts fahrenheit to celcius or celcius to fahrenheit depending upon user's choice Read More »

C++ Program to do arithmetic operations according to user choice using switch case

include<iostream.h> #include<conio.h> void main() {       clrscr(); int a,b; char c; cout<<“Enter any expression(ex:3*7):”; cin>>a>>c>>b; switch(c) { case’+’: cout<<“nResult:”<<a+b; break; case’-‘: cout<<“nResult:”<<a-b; break; case’*’: cout<<“nResult:”<<a*b; break; case’/’: cout<<“nResult:”<<a/b; break; case’%’:  cout<<“nResult:”<<a%b; break; } getch(); }