#include<stdio.h>
#include<math.h>
void main()
{
int ch;
float
e1,e2,x1,x2,k,E,x;
printf("Enter
first number in FPR. \n");
scanf("%f%f",&x1,&e1);
printf("Enter
second number in FPR. \n");
scanf("%f%f",&x2,&e2);
k=fabs(e1-e2);
if(e1>e2)
{
x2=x2/(pow(10,k));
E=e1;
}
else
{
x1=x1/(pow(10,k));
E=e2;
}
printf("Enter
: \n1 - Addition \n2 - Subtraction \n3 - Multiplication \n4 - Division
\n");
scanf("%d",&ch);
switch(ch)
{
case 1 :
{
x=x1+x2;
if(x>0.1)
{
x1=x1/10;
E=E+1;
}
printf("%fe%f ",x,E);
break;
}
case 2 :
{
x=fabs(x1-x2);
if(x<0.1)
{
x1=x1*10;
E=E-1;
}
printf("%fe%f ",x,E);
break;
}
case 3 :
{
x=fabs(x1*x2);
E=e1+e2;
printf("%fe%f ",x,E);
break;
}
case 4 :
{
x=x1/x2;
E=e1-e2;
if(e1>99)
{
printf("Overflow.");
}
if(e1<-99)
{
printf("Underflow.");
}
printf("%fe%f ",x,E);
break;
}
default :
{
printf("Invalid Choice. \n");
}
}
}
No comments:
Post a Comment