#include <stdio.h>
#include <stdlib.h>

void main()
{
int a[400],n,i;
printf("enter the no of elements: ");
scanf("%d",&n);
printf("enter the no: ");
for(i=0;i<n;i++)
{
    scanf("%d",&a[i]);
}
n=n+1;
printf("enter the no: ");
scanf("%d",a[n]);
for(i=0;i<n;i++)
{
    printf("%d",a[i]);
}

}

i inserted elements after that i again inserted its not working.it shows 0 errors but it gets inserted when i try to display compiler stops working see the figure below

On line 16 you need scanf("%d", &a[n-1]);

It was not working because scanf() takes in a pointer to the variable in which you want to write to.

The reason why you need to write to n-1 is because if you have an array that has a length of 5 the indicies that you should be accessing for that range are 0, 1, 2, 3, 4 (note that you do not access 5).

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.