Calculator Program in C

Advertisements

Prime Number Program in C Factorial Program in C

Write Simple Calculator Program in C

In C language you can add, subtract, multiply, divide any number, these all operation you can perform by using switch case.

simple calculator program in c

Calculators are widely used device nowadays. It makes calculations easier and faster. Calculators are used to everyone in daily life. A simple calculator can be made using a C program which is able to add, subtract, multiply and divide, two operands entered by the user. The switch and break statement is used to create a calculator.

C Program for calculator

Calculator Program in C

#include<stdio.h>
#include<conio.h>

void main()
{
char choice;
int a,b,res=0;
clrscr();
printf("Enter First value: ");
scanf("%d",&a);
printf("\n Enter Operator: ");
choice=getch();
printf("\n Enter Second value: ");
scanf("%d",&b);

switch(choice)
{
case '+':
  res=a+b;
  printf("Sum: %d",res);
break;
case '-':
  res=a-b;
  printf("Difference: %d",res);
break;
case '*':
  res=a*b;
  printf("Product: %d",res);
break;
case '/':
  res=a/b;
  printf("Quotient: %d",res);
break;
default:
  printf("Enter Valid Operator!!");
}
getch();
}

Output

Enter First number: 6
Enter operator : +
Enter Second number: 10
Sum: 16

Explanation: In above code choice=getch(); is used for scan or get one value by using getch() function from keyboard, and store in choice.


Prime Number Program in C Factorial Program in C

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements