Thread: do-While not working

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    1

    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();
    	}

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    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.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    You never assign anything to ch.
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 08:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM