+ 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[0]; 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; }

20th Jun 2021, 6:11 PM
Kashyap Kumar
Kashyap Kumar - avatar
11 ответов
+ 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
20th Jun 2021, 7:21 PM
A͢J
A͢J - avatar
+ 1
Your Passion initially take m=0; m=arr[0] may assign garbage value
20th Jun 2021, 6:51 PM
Jayakrishna 🇮🇳
+ 1
🅰🅹 🅐🅝🅐🅝🅣 Yes. But I think problem is with m=arr[0] taking before assigning values so it may assign garbage value so if statement may always false.. Should be taken this after assigning values...
20th Jun 2021, 6:56 PM
Jayakrishna 🇮🇳
0
What about the code is? Where is problem description?
20th Jun 2021, 6:27 PM
Jayakrishna 🇮🇳
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);
20th Jun 2021, 6:28 PM
A͢J
A͢J - avatar
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
20th Jun 2021, 6:33 PM
A͢J
A͢J - avatar
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...
20th Jun 2021, 6:47 PM
Jayakrishna 🇮🇳
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.
20th Jun 2021, 6:52 PM
A͢J
A͢J - avatar
0
Jayakrishna🇮🇳 Read this output description: "Print the remainder when sum is divided by the maximum element." So result will be always 0
20th Jun 2021, 6:54 PM
A͢J
A͢J - avatar
0
Jayakrishna🇮🇳 Yes you are right. We have to first store input in an array then after that we have to do operation.
20th Jun 2021, 6:59 PM
A͢J
A͢J - avatar
0
🅰🅹 🅐🅝🅐🅝🅣 it meaning only to take reminder of sum divided by max. You may confusing here...
20th Jun 2021, 6:59 PM
Jayakrishna 🇮🇳