Search & Find out

Thursday, December 3, 2009

Absolute, Relative and Percentage Errors



#include "stdio.h"
#include "conio.h"
#include "math.h"


void main()
{
int p,i,mx,a;
float c[100],xa,xc,fx,fxa,abs,rel,per;
clrscr();

 printf("Welcome to find Absolute, Relative & Percentage Errors\n\n");

 printf("Enter the maximum power\n\t") ;
 scanf("%d",&mx);

 p=mx;

     for(i=0;i<=mx;i++)
     {
    if(p==0)
    {
     printf("Enter the constant no.=\t");

     scanf("%f",&c[i]);
     }

     else
     {
     printf("Enter the coefficient of the term %d = \t",p);
     scanf("%f",&c[i]);
     p--;
     }
     }


     printf("\n Enter the X acctual & X calculated = \n");
     scanf("%f\n%f",&xa,&xc);


     p=mx;
 tej:
     mx=p;
     for(i=0,fx=0;i<=p;i++,mx--)
     {
       fxa=c[i] * pow(xa,mx);
       fx=fx+fxa;
     }

     if(xa!=xc)
     {
      printf("\nThe value of X acctual is =  %f\n",fx);
      xa=xc;
      abs=fx;
      rel=fx;
      goto tej;
     }

     printf("The value of X calculated is =  %f\n",fx);

    abs=fabs(abs-fx);
    rel=abs/fabs(rel);
    per=rel*100;

    printf("The values of the \n\nAbsolute Error is %f \nRelative Error is %f \nPercentage Error is %f ",abs,rel,per);

  getch();

  }



Download the executable (.exe)  file for this program..
download

0 comments:

Post a Comment

 

My Blog List

Term of Use