Pages

Friday, 9 January 2015

C Program For Calclulator

/* Calculator program in C */

For any query regarding c/c++ feel free to contact me on khimanichirag@gmail.com or comment below. I try my best to solve it.



 #include <stdio.h>  
 #include <conio.h>  
 void sum(int a, int b);  
 void mul(int a, int b);  
 void div(int a, int b);  
 void sub(int a, int b);  
 void main()  
 {  
   int n1,n2,choice;  
   clrscr();  
   printf("Enter first number: ");  
   scanf("%d",&n1);  
   printf("\nEnter second number: ");  
   scanf("%d",&n2);  
   printf("\n\nChoose your operation: ");  
   printf("\n1.Addition");  
   printf("\n2.Subtraction");  
   printf("\n3.Multiplication");  
   printf("\n4.Division");  
   scanf("%d",&choice);  
   switch(choice)  
   {  
     case 1:  
       sum(n1,n2);  
       break;  
     case 2:  
       sub(n1,n2);  
       break;  
     case 3:  
       mul(n1,n2);  
       break;  
     case 4:  
       div(n1,n2);  
       break;  
     default:  
       printf("Please enter the valid choice next time..");  
   }   
   getch();  
 }  
 void sum(int a, int b)  
 {  
   printf("The sum of %d and %d is: %d",a,b,a+b);  
 }  
 void sub(int a, int b)  
 {  
   printf("The subtraction of %d and %d is: %d",a,b,a-b);  
 }  
 void mul(int a, int b)  
 {  
   printf("The multiplication of %d and %d is: %d",a,b,a*b);  
 }  
 void div(int a, int b)  
 {  
   if(b!=0)  
     printf("The division of %d and %d is: %d",a,b,a/b);  
 }  

No comments:

Post a Comment