Wednesday 20 May 2015

How to calculate the Absolute Error and Relative Error By Using C Programing

User is asked to input a number between 4.01 and 4.03.By mistake user gives a number which is outside this range but >4 but <5.


Solution


#include<stdio.h>
#include<conio.h>
#include<math.h>
#define MAX 5
void main()
{
clrscr();
float b,c,a[MAX];
for(int i=0;i<=5;i++)
{
printf("Please Enter a Value Between 4 & 5 \n");
scanf("%f",&a[i]);
if((a[i]<4)||(a[i]>5))
break;
else if((a[i]<=4.03)&&(a[i]>=4.01))
printf("No Error Found In The Given Range \n");
else if(a[i]>4.03)
{
b=(a[i]-4.03)/4.03;
printf(" The Relative Error is: %f \n",b);
}
else if(a[i]<4.01)
{
c=(4.01-a[i])/4.01;
printf(" The Relative Error is: %f \n",c);
}
}
}

1 comment:

  1. please how do i do it for the Absolute Error and Relative Error of functions. need help

    ReplyDelete