Wednesday, December 3, 2014

Numeric :Gauss Seidel

 

Gauss Seidel

 

#include<stdio.h>
int main()
{
 
    double a[50],b[50],c[50],X1,X2,X3,eax1,eax2,eax3,p,q,r;
    int i,n=4;
   // freopen("input.txt","r",stdin);
//printf("Enter length :");
//scanf("%d",&n);
//............................
printf("Enter 1st equation :");
for(i=0;i<n;i++)
{
scanf("%lf",&a[i]);
}
//..........................
printf("Enter 2nd equation :");
for(i=0;i<n;i++)
{
scanf("%lf",&b[i]);
}
//...........................
printf("Enter 3rd equation :");
for(i=0;i<n;i++)
{
scanf("%lf",&c[i]);
}
printf("ENter the value of X1 :");
scanf("%lf",&X1);
printf("ENter the value of X2 :");
scanf("%lf",&X2);
printf("ENter the value of X3 :");
scanf("%lf",&X3);
 
//...........................
X1=p;
X2=q;
X3=r;
 
 
X1=((a[3]-(a[2]*X2)-(a[1]*X3))/a[0]);
 
printf("X1 is %lf\n",X1);
 
X2=((b[3]-(b[2]*X3)-(b[0]*X1))/b[1]);
printf("X2 is %lf\n",X2);
 
X3=((c[3]-(c[1]*X2)-(c[0]*X1))/c[2]);
printf("X2 is %lf\n",X3);
//...........................
eax1=(((X1-p)/X1)*100);
eax2=(((X2-q)/X2)*100);
eax3=(((X3-r)/X3)*100);
printf("eax1=%.1lf\n",eax1);
printf("eax2=%.1lf\n",eax2);
printf("eax3=%.1lf\n",eax3);
return 0;
}

No comments:

Post a Comment