pTutorial

New way to learn C programming

C Program To make Simple Calculator

User define C program to make simple calculator, that perform basic operation like addition, multiplication, subtraction and division.


 //C-program-to-make-simple-calculater 
#include <stdio.h>
#include <conio.h>
#include <process.h>
void main()
{
int final_result,x,y,m;
printf("Enter two numbers : ");
scanf("%d%d",&x,&y);
while(1)
{
 
printf(" \nFor Addition press : 1\n");
printf(" For Subtraction press : 2\n");
printf(" For multiply press: 3\n");
printf(" For division press: 4\n");
printf(" For exit press: 5 \n");
printf("Enter your choice:");
scanf("%d",&m);
 
switch(m)
{
case 1:
final_result=x+y;
printf("sum = %d",final_result);
break;
 
case 2:
final_result=x-y;
printf("subtraction = %d",final_result);
break;
 
case 3:
final_result=x*y;
printf("multiple = %d",final_result);
break;
 
case 4:
final_result=x/y;
printf("division = %d",final_result);
break;
 
default:
printf(" wrong input");
    exit(0);
}
 
}
getch();

Download C Calculator Program

Output of program

Simple C calculator | pTutorial

In this program first take two integer by using scanf function after that put all the code into the while loop and pass the true condition and make it infinite loop for run this code again and again, put some printing statement and enter your choice after that put four cases and at last default case that terminate the program because of exit statement.

See Also

Php checkbox and radio button   |   Java array example for interview questions   |   Jquery tutorial

QUOTES OF THE DAY

Knowledge itself is a power.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER