Im not sure what Ive done wrong but I'm trying to display my array but the program keeps ending so I cant see if its actually working. Im sure its a little mistake - Any help or suggestions will be appreciated.

# include <stdio.h>
# define MAX 100
int main(void)
{
    int array[MAX],i,n;

    printf("\n Enter Array Size: ",MAX);
 
    scanf("%d", &n); //Allows user to choose Array Size
 
    for(i = 0; i < n; i++)
    {
       printf("\n Enter %d value: ",i+1); 
       scanf("\n%d", &array[i]); //Allows user to enter values into array
       }
       printf("%d",&array[i]); //Trying to display the array but program keeps ending not sure what Im doing wrong.
 
       return 1;

}

Thanks
TrueCoding

Recommended Answers

All 6 Replies

There you go: i have written where i made the change

# include <stdio.h>
# define MAX 100
int main(void)
{
    int array[MAX],i,n;
 
    //printf("\n Enter Array Size: ",MAX);
 
    scanf("%d", &n); //Allows user to choose Array Size
 
    for(i = 0; i < n; i++)
    {
       printf("\n Enter %d value: ",i+1); 
       scanf("\n%d", &array[i]); //Allows user to enter values into array
       printf("%d",array[i]); // you had an "&" here.
 
    }
       
     return 1;
 
}

Also, im not sure why you had used the MAX in the printf, so i just commented it.

Ok thanks for that Myk but for some reason its not displaying my array it just says some random numbers?

Basically this is the code but its not displaying my array just some random numbers.

# include <stdio.h>
# define MAX 100
int main(void)
{
    int array[MAX],i,n;

    printf("\n Enter Array Size: ",MAX);
 
    scanf("%d", &n);
 
    for(i = 0; i < n; i++)
    {
       printf("\n Enter %d value: ",i+1); 
       scanf("\n %d", &array[i]);
       }
       printf("\n %d",array[i]);
       getch();
       return 1;
}

Needs a bit of touch up:

Basically this is the code but its not displaying my array just some random numbers.

Let's use MAX of 10, so you don't have to enter lots of numbers yet ;)

# include <stdio.h>
# define MAX 10
int main(void)
{
    int array[MAX],i,n;
    /* your array size is already set at MAX integers (0 through MAX-1) */
    //printf("\n Enter Array Size: ",MAX);
      
    for(i = 0; i < MAX; i++)
    {
       printf("\n Enter %d value: ",i+1); 
       scanf("%d", &array[i]);
    }
    //now print out the array
    putchar('\n');
    for(i = 0; i < MAX; i++)
    {
       printf("%3d  ",array[i]); 
    }
    getch();
    return 0;
}

By convention return 0 means run was normal. Anything else may be an error.

Thankyou Very much problem solved!

You're quite welcome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.