Tuesday, January 26, 2016

Calculator with C Language

Here I am with one program today :). And here is the code how to make simple calculator. Actually I copied the code from here, and tried to understand it. So simple and make sense. 
#include<stdio.h>
int main()
{
/*This is a calculator programme. Calculator is able to perform the operation of two numbers*/
int num;float a,b,c;
printf("Hello World this is a calculator ");
printf("\nchoose a number from the menu to operate the desired function");
printf("\npress 1 for addition\npress 2 for subtraction\npress 3 for multiplication\npress 4 for division \n");
scanf("%d",&num);
/*The operation is performed using the switch case method*/
switch(num)
{
case 1:
printf("enter two numbers \n");
scanf("%f%f",&a,&b);
c= a+b;
printf("the addition of two numbers is %f",c);
break;
case 2:
printf("enter two numbers \n");
scanf("%f%f",&a,&b);
c=a-b;
printf("the subtraction of two numbers is %f",c);
break;
case 3:
printf("enter two numbers \n");
scanf("%f%f",&a,&b);
c=a*b;
printf("the multiplication of two numbers is %f",c);
break;
case 4:
printf("enter two numbers \n");
scanf("%f%f",&a,&b);
c=a/b;
printf("the division of two numbers is %f ",c);
}
}
view raw calculator.c hosted with ❤ by GitHub

No comments: