Simple Calculator Program in C

This is the simple calculator program in c. It performs addition, subtraction, multiplication, and division of integer values.

Simple Calculator Program in C

Source Code:

// simple calculator program in c
#include <stdio.h>

// calci function body 
int calci(int num1, int num2, int ch){
       int res;

       // Swithc case for the operations
       switch (ch){

             // Addition
             case 1:
             res = num1 + num2;

             // Subtration
             case 2:
             res = num1 - num2;

             // Multiplication
             case 3:
             res = num1 * num2;

             // Division 
             case 4:
             res = num1 / num2;

            // If choice is incorrect
            printf("\nEnter correct choise from(1-4)");

     // Return result of operation to main
     return res;

void main() {
       // declare variables used in program 
       int num1, num2, res, ch;

       // Enter first number
       printf("Enter the first number=");

       // Enter second number
       printf("Enter the second number=");

       // Choose your operation to perform form (1-4)
       printf("\n\n1: Addition(+)\n2: Subtraction(-)\n3: Multiplication(X)\n4: Division(÷)\n\nEnter your choice:");

       // Calling calci funtion for operation 
      // And store result of returned result by calci function 
      res = calci(num1,num2,ch);

      // statement to print the result of operation
      printf("\n\nThis is your result for chosen operation:%d",res);


Enter the first number=12
Enter the second number=12

1: Addition(+)
2: Subtraction(-)
3: Multiplication(X)
4: Division(÷)

Enter your choice:1


This is your result for chosen operation:24

Recommended Post

Posted in: C