codescracker


c

C Program to Make Simple Calculator



« Previous Program Next Program »


Make Simple Calculator in C

To make a simple calculator in C programming which performs basic four mathematical operations, use the switch case to identify the input operator to perform required calculation then display the result

C Programming Code to Make Simple Calculate

Following is a simple C program which is a menu-driven program based on simple calculation like addition, subtraction, multiplication and division according to user's choice:

C Program Four Function Calculator

/* C Program - Make Simple Calculator */
		
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
	clrscr();
	float a, b, res;
	char choice, ch;
	do
	{
		printf("1.Addition\n");
		printf("2.Subtraction\n");
		printf("3.Multiplication\n");
		printf("4.Division\n");
		printf("5.Exit\n\n");
		printf("Enter Your Choice : ");
		scanf("%c",&choice);
		switch(choice)
		{
			case '1' : printf("Enter two number : ");
				scanf("%f%f",&a,&b);
				res=a+b;
				printf("Result = %f",res);
				break;
			case '2' : printf("Enter two number : ");
				scanf("%f%f",&a,&b);
				res=a-b;
				printf("Result = %f",res);
				break;
			case '3' : printf("Enter two number : ");
				scanf("%f%f",&a,&b);
				res=a*b;
				printf("Result = %f",res);
				break;
			case '4' : printf("Enter two number : ");
				scanf("%f%f",&a,&b);
				res=a/b;
				printf("Result = %f",res);
				break;
			case '5' : exit(0);
				break;
			default : printf("Wrong Choice..!!");
				break;
		}
		printf("\n------------------------------------\n");
	}while(choice!=5 && choice!=getchar());
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program to make simple calculator

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test