#include <stdio.h> #include <stdlib.h> int main(){ int a=100; int *n=(int*)malloc(100*sizeof(int)); for(int i=0;i<100;i++){ scanf("%d", &n[i]); if(n[i]==42){ a=i++; break; }} for(int i=0;i<a;i++){ printf("%d\n", n[i]); } return 0; }
Your code is AC. Maybe you submited other code then pasted here?
What would happen if there were more than 100 integers before the appearance of 42?
I’m not suggesting you make the array bigger, I suggesting you do away with the array entirely.