Saturday, December 31, 2011

Calculator in 'C'

Example



#include<stdio.h>
#include<conio.h>
void main()
{
int no;
float a,b,c;
clrscr();
printf("Enter the value of a:");
scanf("%f",&a);
printf("Enter the value of b:");
scanf("%f",&b);
printf("=======================OPERATION ARE===================\n");
printf("\n1.Addition");
printf("\n2.Subtraction");
printf("\n3.Multiplication");
printf("\n4.Division");
printf("\n======================================================\n");
printf("Enter the operation you want to do:");
scanf("%d",&no);
switch(no)
{
case 1:
{
      c=a+b;
      printf("\nAddition of two number is:%.f",c);
break;
}
case 2:
{
if(a>b)
{
c=a-b;
}
else
{
c=b-a;
}
printf("\nSubtraction of two number is:%f",c);
break;
}
case 3:
{
c=a*b;
printf("\nMultiplication of two number is:%.2f",c);
break;
}
case 4:
{
if(a>b)
{
c=a/b;
}
else
{
c=b/a;
}
printf("\nDivision of two number is:%.2f",c);
break;
}
default:
printf("Enter the proper number");


}
getch();
}
/*========================================================================
OUTPUT
Enter the value of a:3
Enter the value of b:4
=======================OPERATION ARE===================


1.Addition
2.Subtraction
3.Multiplication
4.Division
======================================================
Enter the operation you want to do:2


Subtraction of two number is:1.000000 */

No comments:

Post a Comment