C Program To Develop Simple Calculator Application
Learn How To Write a Simple Calculator Application Program in C Programming Language using Functions and Switch Case. This Code to Develop Simple Calculator Application C Program makes use of three elements listed as follows:
- User Defined Functions
- While Loop
- Switch Case
This C Program For Calculator Application is a very Simple one. It performs the following Operations:
- Addition
- Subtraction
- Multiplication
- Division
- Square
- Cube
- Cube Root
This Simple Calculator Application in C uses a Switch Case to select the appropriate options from the User. Also, this C Code For Simple Calculator uses Functions i.e., User Defined Functions for various operations.
C Program To Develop Simple Calculator Application using Switch Case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | #include<math.h> #include<stdio.h> #include<stdlib.h> int add(void); int subtract(void); int multiply(void); int divide(void); int modulus(void); int square(void); int cube(void); int sqrroot(void); long double num1, num2; int main() { int option_number; while(1) { printf("\nSelect The Operation To Perform\n"); printf("\n01. Addition"); printf("\n02. Subtraction"); printf("\n03. Multiplication"); printf("\n04. Division"); printf("\n05. Modulus Operation"); printf("\n06. Square of a Number"); printf("\n07. Cube of a Number"); printf("\n08. Exit\n"); printf("Enter Your Choice:\t"); scanf("%d", &option_number); switch(option_number) { case 1: add(); break; case 2: subtract(); break; case 3: multiply(); break; case 4: divide(); break; case 5: modulus(); break; case 6: square(); break; case 7: cube(); break; case 8: exit(0); break; default: printf("\nEnter Correct Option\n"); } } return 0; } int add(void) { long double sum; printf("\nEnter 1st Number:\t"); scanf("%Lf", &num1); printf("\nEnter 2nd Number:\t"); scanf("%Lf", &num2); sum = num1 + num2; printf("\nAddition is %Lf\n", sum); } int subtract(void) { long double sub; printf("\nEnter 1st Number:\t"); scanf("%Lf", &num1); printf("\nEnter 2nd Number:\t"); scanf("%Lf", &num2); sub = num1 - num2; printf("\nSubtraction is %Lf\n", sub); } int multiply(void) { long double mul; printf("\nEnter 1st Number:\t"); scanf("%Lf", &num1); printf("\nEnter 2nd Number:\t"); scanf("%Lf", &num2); mul = num1 * num2; printf("\nMultiplication is %Lf\n", mul); } int divide(void) { long double div; printf("\nEnter 1st Number:\t"); scanf("%Lf", &num1); printf("\nEnter 2nd Number:\t"); scanf("%Lf", &num2); div = num1 - num2; printf("\nDivision is %Lf\n", div); } int modulus(void) { int mod; printf("\nEnter 1st Number:\t"); scanf("%Lf", &num1); printf("\nEnter 2nd Number:\t"); scanf("%Lf", &num2); mod = (int)num1%(int)num2; printf("\nRemainder (by Modulus) is %d\n", mod); } int square(void) { long double sqr; printf("\nEnter The Number:\t"); scanf("%Lf", &num1); sqr = num1 * num2; printf("\nSquare is %Lf\n", sqr); } int cube(void) { long double cube; printf("\nEnter The Number:\t"); scanf("%Lf", &num1); cube = num1 * num1 * num1; printf("\nCube is %Lf\n", cube); } |
Output

If you have any compilation errors or doubts in this C Program To Write A Simple Calculator using Switch Case, let us know about it in the Comment Section below.