Funcții

  1. Suma a doua numere
#include <iostream>
int suma(int a, int b) {
    return a + b;
}
int main()
{
    std::cout << suma(3,6);
}

2. Suma unui sir de numere

#include <iostream>
int suma(int a[],int n) {
    int s = 0;
    for (int i = 0; i < n; i++) {
        s = s + a[i];
    }
    return s;
}
int main()
{
    int sir[5] = { 1,4,2,3,5 };
    std::cout << suma(sir,5);
}

3. Maximul unui sir de numere

#include <iostream>
int maxim(int a[],int n) {
    int max = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > max) {
            max = a[i];
        }
    }
    return max;
}
int main()
{
    int sir[5] = { 1,4,12,3,5 };
    std::cout << maxim(sir,5);
}