0% found this document useful (0 votes)
85 views2 pages

Code

Elon, a bank cashier, wants to develop an app that sums a series of integers until -1 is entered. The input consists of space-separated integers, and the output is the total sum followed by a newline. A sample code is provided that successfully implements this functionality.

Uploaded by

svsxdvimal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views2 pages

Code

Elon, a bank cashier, wants to develop an app that sums a series of integers until -1 is entered. The input consists of space-separated integers, and the output is the total sum followed by a newline. A sample code is provided that successfully implements this functionality.

Uploaded by

svsxdvimal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Search course

Type to search
Minimum 3 characters required for search
2.6.3. Sum of Amounts
01:04
Elon, employed as a cashier in a bank, currently relies on a basic calculator that
only adds numbers when the + key is pressed. Elon wishes to create a calculating
app that sums up a series of numbers until he enters the value -1.

Can you assist Elon in developing this app?

Input Format:

The input line reads space-separated integers.

Output Format:

The output is an integer that is the sum of numbers entered till -1.

Note: Print newline character (\n) after output statement.

Sample Test Cases


Test case 1
100 230 150 -1
480⏎
Test case 2
-1
0⏎

SumofAmounts.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17


// write your code here
#include <stdio.h>

int main() {
int num, sum = 0;
while (1) {
scanf("%d", &num);
if (num == -1)
break;
sum += num;
}
printf("%d\n", sum);
return 0;
}

Average time
0.451 s
450.67 ms
Maximum time
0.544 s
544.00 ms
2 out of 2 shown test case(s) passed

4 out of 4 hidden test case(s) passed

Test case 1468 ms

Expected output
100 230 150 -1
480⏎
Actual output
100 230 150 -1
480⏎

Test case 2479 ms

Reason for late submission


Eucs.Learner.Contents.LateSubmissionModal.Input.Placeholder
Please enter at least 15 characters

You might also like