Tuesday, October 25, 2022

Lyc
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

Contact Us

Phone :

+8801716815647
+8801996204467
+8801520731186

Email :

susmoy1025@gmail.com
dishantanjim@gmail.com
sadmansakib7494@gmail.com