2 / 3
Jan 2018
#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;
}
  • created

    Jan '18
  • last reply

    Jan '18
  • 2

    replies

  • 728

    views

  • 3

    users

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.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 39 Jun 29

Want to read more? Browse other topics in C and C++ or view latest topics.