0

What are the mistakes in this code ? Please help

/* C program to find sum of all array elements*/ #include<stdio.h> #define max_size 100 int main() { int n,i,sum=0; int arr[ 5]; //input array size printf ("Enter size of array:"); scanf("%d",&n); //input array elements printf ("Enter elements of array:"); for(i=0;i<n;i++) { scanf("%d",arr[i]); } printf ("Summation of elements in array:"); for(i=0;i<n;i++) { sum+=arr[i]; printf("%d",arr[i]); } printf ("\n"); return 0; }

6th Nov 2022, 6:16 AM
Dipanita Saha
Dipanita Saha - avatar
2 Answers
6th Nov 2022, 6:40 AM
Dipanita Saha
Dipanita Saha - avatar
0
You forgot to add the "&" in the scanf inside the loop. Also since you need to print the sum you should print the value of the sum, not the arr elements. https://code.sololearn.com/cb59yDhMTKrw/?ref=app
6th Nov 2022, 6:26 AM
The future is now thanks to science
The future is now thanks to science - avatar