Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write program in C #121

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions programs/C/calculator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include<stdio.h>
void Input(){
printf("Type number to choose the algorithm\n");
printf( " 1. + \n 2. - \n 3. *\n 4. / \n 5.Exit\n InputNum: ");
}
int main()
{
int InputNum=0;
float a=0;
float b=0;
float result=0;
do{
Input();
scanf("%d", &InputNum);
switch(InputNum){
case(1):
printf("Enter First Number: ");
scanf("%f", &a);
printf("Enter Second Number: ");
scanf("%f", &b);
result = a + b;
printf("%.2f + %.2f = %.2f\n",a , b, result);
break;
case(2):
printf("Enter First Number: ");
scanf("%f", &a);
printf("Enter Second Number: ");
scanf("%f", &b);
result = a - b;
printf("%.2f - %.2f = %.2f\n",a ,b, result);
break;
case(3):
printf("Enter First Number: ");
scanf("%f", &a);
printf("Enter Second Number: ");
scanf("%f", &b);
result = a * b;
printf("%.2f * %.2f = %.2f\n",a ,b, result);
break;
case(4):
printf("Enter Dividend: ");
scanf("%f", &a);
printf("Enter Divisor: ");
scanf("%f", &b);
if (b == 0){
printf("Please check the divisor that can not be zero.\n");
}
else{
result = a / b;
printf("%.2f / %.2f = %.2f\n",a ,b, result);
}
break;
case(5):
printf("Thank you for using code !!\n");
break;
default:
printf("Invalid number, please choose again.\n");
}
}while(InputNum);
return 0;
}