about summary refs log tree commit diff
path: root/usth/ICT2.1/labwork/1/Ex2.c
blob: f783946c414773cf3aca091be46d1dde6eb2f8d0 (plain) (blame)
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
/*
 * Read an array of n int from stdin and print its sum to stdout
 * This is free and unencumbered software released into the public domain.
 */

#include <stdio.h>
#include <stdlib.h>

int sum(int n, int *a)
{
	int s = 0;
	while (n--)
		s += a[n];
	return s;
}

int main()
{
	int n;
	scanf("%d", &n);

	int *a = malloc(n * sizeof(int));
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);

	printf("%d\n", sum(n, a));
	return 0;
}