0% found this document useful (0 votes)
6 views4 pages

Tema

The document discusses 5 problems (Ns1-Ns5) involving calculating sums of numbers and their properties. Multiple algorithms are presented to calculate sums using for loops and while loops, including iterating through digits of numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Tema

The document discusses 5 problems (Ns1-Ns5) involving calculating sums of numbers and their properties. Multiple algorithms are presented to calculate sums using for loops and while loops, including iterating through digits of numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Ns1 S = 1x2 + 2x3 + ….

+ n x (n+1), n citit de la tastatura

for (i=1; i<=n; i++)

s = s + i* (i+1)

Ns3 S = 1+ x + x2 +x3+ ….. +xn , unde x, n citite

s =1; p = 1;

for (i=1; i<=n; i++)

{ p = p*x;

s = s+p; }

n= 2154 12 3

Ns4 s = 1! + 2! +3!+ 4!+ … +i! + …+x! , x citit

3! =1*2*3

4! = 1*2*3*4 s =0

for (i=1; i<=x; i++)

{ p=1;

for (j=1; j<=i; j++)

p = p*j;

s = s + p;}
Metoda II

s=0; p=1;

for (i=1; i<=x; i++)

{ p=p*i;

s =s+p;}

Ns5 Se citeste un numar n, cu cel mult 9 cifre. Sa se afiseze media armonica

n = 2749 s= 1*9 + 2*4 + 3*7 + 4*2 s=22 4

s=0; k=0;

while ( n!=0) // 2 %10 =2 2/10 =0

{ c = n%10;

k =k+1; // Numara cifrele numarului n

s = s + c*k;

n = n/10; }

cout << s;
Ia5)

for (i=1; i<=n; i++) 435, 12, 78, 90, 5, 247, 532

{ s=0;

x=v[i];

while( x!=0)

{ s=s+ x%10;

x=x/10;}

cout<< s;}

You might also like