Thread: i need help in a array prrogram

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    3

    i need help in a array prrogram

    Hi all
    i'm new to cprogramming
    I'm trying to write a program that should ask as input an array of int and should display the values of that array ordered by decreasing size <
    I cant get the program to work
    Do u think u can help me
    here's my code


    #include <stdio.h>
    #define nb 5
    int i , j , n , min ,minInd;

    void main(void)
    {
    int E[nb] ;

    printf("enter numbers");
    for (i=0; i<5 ; i++)
    {scanf("%d", E[i] );
    min= E[i];
    minInd=i;
    for (j=i+1; j<=n ; j++)
    {
    if (min > E[i])
    min= E[i] ;
    minInd= j ;

    }
    E[minInd]=E[i] ;
    E[i]=min;

    }
    for (i=0; i<5 ; i++)
    printf("%d", E[i]);

    }

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    what kind of error are you getting??

    heres a rough idea

    Code:
    for(i=0;i<5;i++)
    for(j=i+1;j<5;j++)
    if(array[i]>array[j]
     {
      temp=array[i];
      array[i]=array[j];
      array[j]=temp;
     }
    this should do it, i think
    ive not tested it
    -

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Re: i need help in a array prrogram

    Originally posted by jason79
    Hi all
    i'm new to cprogramming
    I'm trying to write a program that should ask as input an array of int and should display the values of that array ordered by decreasing size <
    I cant get the program to work
    Do u think u can help me
    here's my code


    #include <stdio.h>
    #define nb 5
    int i , j , n , min ,minInd;

    void main(void)
    {
    int E[nb] ;

    printf("enter numbers");
    for (i=0; i<5 ; i++)
    {scanf("%d", E[i] );
    min= E[i];
    minInd=i;
    for (j=i+1; j<=n ; j++)
    {
    if (min > E[i])
    min= E[i] ;
    minInd= j ;

    }
    E[minInd]=E[i] ;
    E[i]=min;

    }
    for (i=0; i<5 ; i++)
    printf("%d", E[i]);

    }
    I might be wrong, but I think you should put an address here instead of a variable, like this:

    scanf("%d", &E[i] );

    (Notice the &)
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM