-
do-While not working
Plz see this program here do-while loop not working :
Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,j,k,n,max;
float factor,sum,a[10][10],t,x[10];
char ch;
do
{
printf("\n Enter n: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n+1;j++)
{
printf("\nEnter %d row %d col element\n",i+1,j+1);
scanf("%f",&a[i][j]);
}
}
printf("The Input is :\n");
for(i=0;i<n;i++) {
for(j=0;j<n+1;j++)
printf(" %f\t ", a[i][j]);
printf("\n");
}
for(i=0;i<n;i++)
{
max=i;
for(j=i+i;j<n;j++)
if(fabs (a[j][i]) > fabs(a[max][i]))
max=j;
for(j=0;j<n+1;++j)
{
t=a[max][j];
a[max][j]=a[i][j];
a[i][j]=t;
}
}
printf("\n The Net argument matrix \n");
for(i=0;i<n;i++)
{
for(j=0;j<n+1;j++)
printf(" %f \t ",a[i][j]);
printf("\n");
}
for(k=0;k<n;k++)
{
for(i=k+1;i<n;i++)
{
factor=a[i][k]/a[k][k];
for(j=k;j<n+1;j++)
a[i][j]-=factor*a[k][j];
}
}
x[n-1]=a[n-1][n]/a[n-1][n-1];
for(i=n-2;i>=0;i--)
{
sum=0;
for(j=i;j<n+1;j++)
sum+=a[i][j]*x[j];
x[i]=(a[i][n]-sum)/a[i][i];
}
for(i=0;i<n;i++)
printf("\n X%d = %g\n",i+1,x[i]);
} while (ch=='y' || ch=='Y');
getch();
}
-
1) Whats the question?
2) What are the errors?
3) Indent properly (you know how hard that is to read?)
4) What is it suppose to do?
Formatting your code is also a factor in how well you write code.
-
You never assign anything to ch.
Kurt