+ 1

Dynamic memory, can you spot the error?

// #include <stdio.h> #include <stdlib.h> int main() { int n; scanf("%d\n", &n); int *arr; arr= (int*)calloc(n, sizeof(int)); int large=*arr; if(arr==NULL) { printf("Memory Allocation Failed!"); } else{ for(int i=0;i<n;i++) { printf("%d",i); scanf("%d\n",arr+i); } for(int i=1; i<n; ++i){ if(*arr<*(arr+i)) large=*(arr+i); } } printf("Largest no. is: %d", large); return 0; }

8th Jan 2020, 6:38 PM
Tom
Tom - avatar
1 Resposta
0
After if statement add- else large = *arr;
8th Jan 2020, 7:13 PM
Avinesh
Avinesh - avatar