Gauss - Seidal Method in C

 // Gauss-Seidal Method

    #include<stdio.h>
    main()
    {
        int n,i,j,k;
        float a[20][20],x[20],m,s=0.0;
        printf("\nProgram to implement Gauss-Seidal Iterative Method : \n");
        printf("\nEnter the order of the co-efficient matrix : ");
        scanf("%d",&n);
        printf("\nEnter the element of the augmented matrix row-wise : ");
        for(i=1;i<=n;i++)
            for(j=1;j<=n+1;j++)
                scanf("%f",&a[i][j]);
        printf("\nEnter the initial approximation : ");
        for(i=1;i<=n;i++)
            scanf("%f",&x[i]);
        for(k=1;k<=15;k++)
        {
            for(i=1;i<=n;i++)
            {
                s=a[i][n+1];
                for(j=1;j<=n;j++)
                {
                    if(j!=i)
                    s=s-a[i][j]*x[j];
                }
                x[i]=s/a[i][i];
            }
        }
        printf("\nThe required soln :\n");
        for(i=1;i<=n;i++)
            printf("x[%d] = %6.4f\n",i,x[i]);
    }

Top