Thread: very very very easy for anexpert in c

  1. #1
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159

    Exclamation very very very easy for anexpert in c

    /*my english is not correct but ...*/
    /*we have an error into tri boucle*/
    /*this program can organise a table in croissant order*/
    #include "stdio.h"
    #define n 1000
    void main()
    {/*long tab*/
    int na,i,i1,i2,k,x,t[n];
    while((na>n)||(na<=0))
    {
    printf("donner long tab\n");
    scanf("%i",&na);
    }
    for(i=0;i<na;i++)
    {/*data table*/
    printf("donnez contenue case %i",i);
    scanf("%i",&t[i]);
    }
    k=1;

    while(k!=0){/*boucle ordering table ----->you can find an error here*/
    for(i1=0;i1<na;i1++)
    {

    while(k!=0)
    {
    k=0;
    for(i2=1;i2<na;i2++)
    {
    if(t[i2]<t[i1])
    {
    k=1;

    x=t[i2];
    t[i2]=t[i1];
    t[i1]=x;
    printf("k");
    }
    }
    }
    }
    }
    for(i=0;i<na;i++)
    {
    printf(" %i ",t[i]);
    }
    }
    Last edited by enjoy; 04-16-2004 at 10:54 AM.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    134
    could u please translate into english as to what issue u are having ?

  3. #3
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    help me please i have just translate it in english !!!....(my english is no correct but i try ....)

  4. #4
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    first, please use CODE tags, its quite troublesome to read without indentation...

    Can you explain what it is you are trying to accomplish with this:
    Code:
    while(k!=0){
    for(i1=0;i1<na;i1++)
    {
    
      while(k!=0) 
      {
        k=0;
        for(i2=1;i2<na;i2++)
        {
            if(t[i2]<t[i1])
            {
              k=1;
    
              x=t[i2];
              t[i2]=t[i1];
              t[i1]=x;
              printf("k");
            }
          }
        }
      }
    } 
      for(i=0;i<na;i++)
      {
        printf(" %i ",t[i]); 
      }
    }
    Last edited by nonpuz; 04-16-2004 at 11:13 AM.

  5. #5
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    i try to order the table in order
    ====>you have missing the
    k=1;
    ***********please help me to order this table

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Study this and see if it helps you.
    Code:
     #include <stdio.h>
     
     #define SIZE 1000
     
     int main(void)
     {
       int num = 1;
       int myArray[SIZE];
       int Counter = 0;
       int i;
       int j;
       
       while (num > 0 && Counter < SIZE)
       {
         printf ("Enter number, or 0 to end:"); 
         fflush(stdout);
         if (scanf("%d", &num) == 1)
         {
           if (num > 0)
           {
             myArray[Counter] = num;
             Counter++;
           }
         }
         else
         {
           while (getchar() != '\n')
             ;
         }
       }
       
       for (i = 0; i < Counter; i++)
       {
         for (j = 0; j < Counter - i - 1; j++)
         {
           if (myArray[j] > myArray[j+1])
           {
             int temp = myArray[j];
             myArray[j] = myArray[j+1];
             myArray[j+1] = temp;
           }
         }
       }
       
       for (i = 0; i < Counter; i++)
       {
         printf(" %d ", myArray[i]);
       }
       
       return 0;
     }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Easy String position question...
    By Striph in forum C Programming
    Replies: 4
    Last Post: 05-11-2009, 08:48 PM
  2. Java vs C to make an OS
    By WOP in forum Tech Board
    Replies: 59
    Last Post: 05-27-2007, 03:56 AM
  3. Easy question, (should be) easy answer... ;-)
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-12-2002, 09:36 PM
  4. Replies: 20
    Last Post: 05-25-2002, 07:14 PM
  5. EASY GUI development.. like with Qt?
    By rezonax in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2001, 01:18 PM