Răspuns:
#include <iostream>
using namespace std;
int n, suma, i;
int main ()
{
cout << "n=";
cin >> n;
for (i = 1; i <= n; i++) {
suma = suma + i;
}
cout << suma;
return 0;
}
Exemplu n=6 suma=21 (1+2+3+4+5+6)
#include <iostream>
using namespace std;
int n, suma, produs = 1, i;
int main ()
{
cout << "n=";
cin >> n;
for (i = 1; i <= n; i++)
if (i%2 == 1) {
suma = suma + i;
produs = produs*i;
}
cout << "suma=" << suma << endl << "produs=" <<produs;
return 0;
}
Exemplu n=6 suma=9 (1+3+5) produs=15 (1×3×5)