Академический Документы
Профессиональный Документы
Культура Документы
Date:
Time:
Operating System:
Compiler:
Total points:
Question 1 (1 point)
Write a program that reads numbers which are in the range 0 to 100, till it encounters -1. Print the sum
of all the integers that you have read before you have encountered -1.
INPUT:
A sequence of integers separated by whitespace. There may be other integers following -1.
OUPUT:
Sum of all integers in the sequence before you encounter -1. Any integer that is input after -1 in the
sequence should be ignored.
CONSTRAINTS:
Utmost 10 integers will be given in the input. One of them is guaranteed to be a -1.
Inputs will be in the range 0 to 100 (both included.)
Sample Test Cases
Test Case 1
Test Case 2
Test Case 3
Test Case 4
Input
Output
2 -1 2 3
-1 4 5
10 3 4 -1
17
2 2 3 4 5 6 -1 7 8 9
22
Input
Output
Test Case 1
5
12131
Test Case 2
6
7 7 -2 3 1 1
Test Case 3
4
2323
7
8
9
10
11
12
13
14
15
16
Output for the above matrix: 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10
INPUT:
First line contains two integers M and N separated by whitespace. The next M lines contain elements of
matrix A, starting with the topmost row. Within each row, the elements are given from left to right.
OUTPUT:
Elements of the matrix printed in a spiral order. All the elements should be separated by whitespace.
CONSTRAINTS:
1 <= M <= 5, 1 <= N <= 5. Elements in the matrix will be in the range [-100,100]
Sample Test Cases
Input
Output
33
012
Test Case 1
012345678
783
654
22
Test Case 2
1 10
1 10 5 3
35
44
7812
Test Case 3
3431
7812167945134382
1286
5497
11
Test Case 4
20
20