GAUSS SEIDEL

If you have any queries please leave a message here
Your Message
×



USING ARRAY

#include<stdio.h>
void main()
{
int n,i,j,k,iteration;
float array1[10][10],array2[10],array3[10],temp;
printf("\nEnter the number of equation present...");
scanf("%d",&n);
printf("\nEnter the number of iteration you want to perform...");
scanf("%d",&iteration);

//Input values present in the equations as mention
for(i=0;i<n;i++)
{
printf("\nEnter Equation %d",(i+1));
for(j=0;j<n;j++)
{
printf("\nEnter the value attach with x%d...",(j+1));
scanf("%f",&array1[i][j]);
}
printf("\nEnter the value which is present after '=' symbol...");
scanf("%f",&array2[i]);
}

//Initialize the value of x1, x2, x3, . . . etc.
for(i=0;i<n;i++)
{
array3[i] = 0;
}

//Doing calculation using Gauss Seidel Method
for(i=1;i<=iteration;i++)
{
for(j=0;j<n;j++)
{
temp=array2[j];
for(k=0;k<n;k++)
{
if(k!=j)
{
temp = temp - (array1[j][k] * array3[k]);
}
}
array3[j] = temp / array1[j][j];
}

//After calculation print the value of x1, x2, x3, . . . etc. for each iteration
printf("\nIteration %d\t",i);
for(j=0;j<n;j++)
{
printf("x%d = %f ",(j+1),array3[j]);
}
}
}


USING POINTER

#include<stdio.h>
void main()
{
int n,i,j,k,iteration;
float *array1,*array2,*array3,temp;
printf("\nEnter the number of equation present...");
scanf("%d",&n);
printf("\nEnter the number of iteration you want to perform...");
scanf("%d",&iteration);

//Dynamic memory allocation
array1=(float *)malloc(n * n * sizeof(float));
array2=(float *)malloc(n * sizeof(float));
array3=(float *)malloc(n * sizeof(float));

//Input values present in the equations as mention
for(i=0;i<n;i++)
{
printf("\nEnter Equation %d",(i+1));
for(j=0;j<n;j++)
{
printf("\nEnter the value attach with x%d...",(j+1));
scanf("%f",(array1 + i*n + j));
}
printf("\nEnter the value which is present after '=' symbol...");
scanf("%f",(array2 + i));
}
for(i=0;i<n;i++)
{
*(array3 + i) = 0;
}

//Doing calculation using Gauss Seidel Method
for(i=1;i<=iteration;i++)
{
for(j=0;j<n;j++)
{
temp = *(array2 + j);
for(k=0;k<n;k++)
{
if(k!=j)
{
temp = temp - (*(array1 + j*n + k) * *(array3 + k));
}
}
*(array3 + j) = temp / *(array1 +j*n + j);
}

//After calculation print the value of x1, x2, x3, . . . etc. for each iteration
printf("\nIteration %d\t",i);
for(j=0;j<n;j++)
{
printf("x%d = %f ",(j+1),*(array3 + j));
}
}
}



ABOUT US

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.


MORE TOPIC


Windows Command

UNIX Command

IGNOU Assignment Solution

IGNOU Question Paper Solution

Solutions of Different Questions


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us