Simple Calculator [C]
Hey there coders welcome to cyber assassin's. I am Lyc from cyber assassin's. The post is about making a simple calculator using "C" programing language.
#Here is the code:
#include <stdio.h>
int main() { char operation; double a, b; printf("Enter the first number\n"); scanf("%lf", &a); printf("Enter the operation you want to do. It must be + - x ÷\n"); scanf(" %c", &operation); printf("Enter the second number\n"); scanf("%lf", &b); switch (operation) { case '+': printf("%.2lf+%.2lf=%.2lf\n", a, b, a+b); break; case '*': printf("%.2lfx%.2lf=%.2lf\n", a, b, a*b); break; case '-': printf("%.2lf-%.2lf=%.2lf\n", a, b, a-b); break; case '/': printf("%.2lf÷%.2lf=%.2lf\n", a, b, a/b); break; case 'x': printf("%.2lfx%.2lf=%.2lf\n", a, b, a*b); break; case '÷': printf("%.2lf÷%.2lf=%.2lf\n", a, b, a/b); break; default: printf("Please enter a valid oparator such as + - x ÷\n"); } return 0; }
0 comments:
Post a Comment