Simple Calculator Application C Program

By | April 24, 2016

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:

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division
  5. Square
  6. Cube
  7. 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

#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

Learn How To Make Simple Calculator Application C Program

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.

Recommended Programs
C Program To Delete Vowels From A String
Print Map of India in C Programming
C Program To Solve Tower of Hanoi Algorithm Problem
Sum of Series: 1 + 1/2 + 1/4 + 1/8 … + 1/n
C Program To Generate Floyd’s Triangle
100+ C Programs For Programming Interviews

Let's Discuss