-
Notifications
You must be signed in to change notification settings - Fork 0
/
week 7 in c
85 lines (63 loc) · 1.36 KB
/
week 7 in c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<1> Array Reversal
Input Format
The first line contains an integer, , denoting the size of the array. The next line contains space-separated integers denoting the elements of the array.
Output Format
the output is handled by the code given in the editor, which would print the array.
Sample Input 0
6
16 13 7 2 1 12
Sample Output 0
12 1 2 7 13 16
Sample Input 1
7
1 13 15 20 12 13 2
Sample Output 1
2 13 12 20 15 13 1
Sample Input 2
8
15 5 16 15 17 11 5 11
Sample Output 2
11 5 11 17 15 16 5 15
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int i,n;
long long a[100];
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
for(i=n;i!=0;i--)
{
printf("%lld ",a[i]);
}
<2> Sum of array elements
Input Format
The first line contains an integer, . The next line contains space-separated integers.
Constraints
1 <= n <= 1000 1 <= a[i] <= 1000
Output Format
Print the sum of the integers in the array.
Sample Input 0
6
16 13 7 2 1 12
Sample Output 0
51
#include <stdio.h>
int main(){
int n;
scanf("%d",&n);
int arr[n];
for(int arr_i = 0; arr_i < n; arr_i++){
scanf("%d",&arr[arr_i]);
}
int result = 0;
for(int arr_i = 0; arr_i < n; arr_i++){
result += arr[arr_i];
}
printf("%d", result);
return 0;
}