Basic Calculator Using C Language
#include <stdio.h>
//function to add two numbers
int Add(int a,int b){
return a+b;
}
//function to substract two numbers
int substract(int a,int b){
return a-b;
}
//function to multiply two numbers
int multiply(int a,int b){
return a*b;
}
//function to divide two numbers
int divide(int a,int b){
return a/b;
}
int main(void)
{
int a,b,c;
start:
printf("\n_____calculator_____\n");
printf("press 1 for addition\n");
printf("press 2 for substraction\n");
printf("press 3 for multiplication\n");
printf("press 4 for division\n");
printf("press 5 to quit\n");
scanf ("\n%d", &c);
if (c==1) {
printf ("ADDITION\n");
printf("enter any two number\n") ;
scanf("%d", &a);
scanf("%d",&b);
printf("Addition = %d",Add(a,b));
goto start;
}
else if(c==2){
printf("\nSUBSTRACTION\n");
printf("enter any two number\n") ;
scanf("%d", &a);
scanf("%d",&b);
printf("Substraction = %d",substract(a,b));
goto start;
}
else if(c==3){
printf ("\nMULTIPLICATION\n");
printf("enter any two number\n") ;
scanf("%d", &a);
scanf("%d",&b);
printf("Multiplication = %d",multiply(a,b));
goto start;
}
else if(c==4){
printf("\nDIVISION\n");
printf("enter any two number\n") ;
scanf("%d", &a);
scanf("%d",&b);
printf("Division = %d",divide(a,b));
goto start;
}
else if (c==5){
printf("quitting the program");
goto end;
}
else{
printf ("\ninvalid input");
}
end:
return 0;
}
🔗Link : https://replit.com/@AquaLeagen/Calculator?s=app
Comments
Post a Comment