+ 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; }
1 ответ
0
After if statement add-
else
large = *arr;