Thread: i need help in a array prrogram

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

    Lightbulb 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
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    You program is a bit messy. First of all, to scanf into individual elements of an array, you hav to put ampersand ( & ) in front, like this: scanf("%d", &E[i] );

    If you put the code in code tags i might be able to help more.

  3. #3
    Registered User JasonLikesJava's Avatar
    Join Date
    Mar 2002
    Posts
    175

    Talking


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