 Array Sum | Sololearn: Learn to code for FREE!

+1

# Array Sum

https://code.dcoder.tech/question/5b61e933527d3b5ac5cecda3 Only one test case is getting passed by my solution. #include <stdio.h> int main() { int n, i, sum=0, m; scanf("%d", &n); int arr[n]; m = arr; for(i=0; i<n; i++){ scanf("%d", &arr[i]); sum += arr[i]; if(m<arr[i]){ m = arr[i]; } } printf("%d", sum%m); return 0; }

+3

Jayakrishna🇮🇳 Yes you were right. Description itself is confusing. I have submitted my code and passed all test cases. Your Passion Your code should be like this: (problem in your code is that you are storing garbage value in m) https://code.sololearn.com/coW128L3e9nx/?ref=app

+1

Your Passion initially take m=0; m=arr may assign garbage value

+1

🅰🅹 🅐🅝🅐🅝🅣 Yes. But I think problem is with m=arr taking before assigning values so it may assign garbage value so if statement may always false.. Should be taken this after assigning values...

0

What about the code is? Where is problem description?

0

Your Passion Check explanation again. You have to print reminder when sum is divided by the max value of an array so you have to do this: if (sum % m == 0) printf("%d", sum % m);

0

Jayakrishna🇮🇳 Description is here: Problem Statement You are given an integer array and you have to find the sum of the elements of the array and find the remainder when the sum is divided by the largest number of the array. Input First line contains N, the number of elements. Next line contains N space separated integers (elements of the array). Output Print the remainder when sum is divided by the maximum element. Constraints 1 ≤ n ≤ 100 0 ≤ A[i] ≤ 1000 Sample Input 5 1 2 3 4 5 Sample Output 0

0

Oh. I did not noticed the link. But it's not showing playground only in a few seconds immediately...🅰🅹 🅐🅝🅐🅝🅣 But I think Your Passion is correct .. AJ According to your code, it's always zero. It's asking print reminder only...

0

Jayakrishna🇮🇳 Yes same thing happened with me also so I checked in Challenges section. It may be because we are not logged in there.

0

Jayakrishna🇮🇳 Read this output description: "Print the remainder when sum is divided by the maximum element." So result will be always 0

0

Jayakrishna🇮🇳 Yes you are right. We have to first store input in an array then after that we have to do operation.

0

🅰🅹 🅐🅝🅐🅝🅣 it meaning only to take reminder of sum divided by max. You may confusing here...