switch statement - Basic C Program
C Program to use the computer as calculator. The user input a code +,‒,,/ and values that are to be computed.
/* Program to use the computer as calculator */
#include <stdio.h>
main()
{
int a,b,c=0;
char op;
printf("CALCULATION CODE");
printf("\n+ADD\n‒SUB\n*MUL\n/DIV\n");
printf("Enter Code.....");
scanf("%c",&op);
printf("Enter values.....");
scanf("%d %d",&a, &b);
switch(op)
{ /* switch open */
case '+':c=a+b;
break;
case '‒': c=a‒b;
break;
case '*': c=a*b;
break;
case '/': c=a/b;
break;
} /* switch */
printf("\nResult is.....%d", c);
getch();
} /* main */
OUTPUT
CALCULATION CODE
+ADD
‒SUB
*MUL
/DIV
Enter Code.....+
Enter values.....20 10
Result is.....30
EXPLANATION: In the program the switch statement consists of four options. The option is entered according to user's choice. The four options are addition, subtraction, multiplication and division. Each option contains several operations. Thus statement is executed according to selected choice. In the program the character variable op reads the character entered by the users. According to the entered character, the switch statement is executed and prints the output.
Computer Programming C Laboratory: Basic C Programs : Tag: C Programming : - C Program to use the computer as calculator (switch statement)
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
English Essentials I
EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
தமிழர் மரபு - Heritage of Tamils
UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Calculus
MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I
PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Chemistry I
CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Makerspace
ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming Python
CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Fundamentals of Electrical and Electronics Engineering
EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Mechanical Engineering
ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Civil Engineering
CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing
CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I Laboratory
PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Applied Chemistry I Laboratory
CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electronics and Electrical Engineering
EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing - Laboratory
CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation