I used this code to insert values for array data
, but when I tried inserting the values 8 1 2 3 4 5 6 7 8
(the first number 8 is the size of the array), the output was 00000000
instead of the input values 1 2 3 4 5 6 7 8
. Any idea how I can make the program work?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,i,*data;
scanf("%d", &n);
data=(int *)malloc(sizeof(int)*n);//data[size]
for(i=0;i<n;i++)
{
scanf("%d", &data[i]);
}
for(i=0;i<=n;i++)
printf("%d",data[n]);
printf("\n");
return 0;
}