Ad Code

Program to make a simple calculator

Do you want to make a simple calculator in programming c. If yes then you are at the right place. In this article i will be publishing a simple code in programming c to make a simple calculator. This calculator will only  do some simple tasks like plus, minus, multiply and divide. So, lets get started.

CODE FOR CALCULATOR

Program to make a simple calculator

#include<stdio.h>
#include<conio.h>
void main(){  

    int a,b;
    char c='+';
    printf("enter two no.'s with operator like a-b ");
    scanf("%d%c%d",&a,&c,&b);
   
    switch(c){
    case '+':
    printf("%d + %d = %d\n",a,b,a+b);
    break;
    case '-':
    printf("%d - %d = %d\n",a,b,a-b);
    break;
    case '*':
    printf("%d x %d = %d\n",a,b,a*b);
    break;
    case '/':
    printf("%d / %d = %d\n",a,b,a/b);
    break;
    default:
    printf("entered operator is wrong");
    break;
    }
getch();
}

INPUT/OUTPUT

In this program we don't have to put spaces or we don't have to click enter between no.'s and operator. So, If we input 55-13 the output will be 42.

Program to make a simple calculator

Conclusion

We have to take two variables and one operator and then we have to use jumping statement switch case. 
If you guys find anything wrong in this program please comment below i (wasim ahmad kumar) will try to give you best answer.

Post a Comment

0 Comments

Ad Code