Skip to main content

Use of Switch in C Programming

NOTE: All Codes are written and tested in DEV C++


Switch:



Basic Requirement to learn this code:
1.Switch Case




Example:1:

#include<stdio.h>
main()
{
int choice;


printf("input ur choice man \n1.Add\n2.Display Count Upto \n3.Today Qoutes\n");
scanf("%d",&choice);


switch(choice)
{
case 1: int a,b,sum;
printf("\nenter two no. to add:");
scanf("%d%d",&a,&b);
sum=a+b;
printf("sum=%d",sum);
break;
case 2: int i,n;
printf("\nenter a number upto which u want to print the numbers from one");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf("\n%3d",i);
break;
case 3: printf("\nHonesty is the best policy\n HAVE a good day Sir!!!");
break;

default: printf("Invalid Input");

}}

Comments