Answer: Read n, store the n integers in an array with one loop, then print a[i] followed by a newline in a second loop.
#include <stdio.h>
int main()
{
int n, i, a[100];
printf("Enter the number of elements: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("Enter element %d: ", i + 1);
scanf("%d", &a[i]);
}
printf("The elements are:\n");
for (i = 0; i < n; i++)
{
printf("%d\n", a[i]);
}
return 0;
}
How it works:
a[100] can hold up to 100 integers, so n should be at most 100.- The first
for loop reads the values into a[0] to a[n-1]. - The second loop prints each element with
"%d\n"; the \n moves to a new line, so every number appears on its own line.
Sample run: entering n = 3 and the values 5, 12, 7 prints 5, 12 and 7 on three separate lines.