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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} | |
No comments:
Post a Comment