RSS

Suma numerelor impare

08 Apr

Modificând puţin programul anterior, obţinem algoritmul care calculează suma primelor n numere impare…

De exemplu dacă n = 5 atunci suma = 1+3+5+7+9 = 25.

#include<iostream.h>
#include<conio.h>
int main()
{ int n,i,contor=0,suma=0;
 cout<<"n="; cin>>n;
 i=1;
 while(contor!=n)
 { suma=suma+i;
 i=i+2;
 contor++; }
 cout<<"Suma primelor "<<n<<" numere impare este: "<<suma;
 getch(); }
About these ads
 
1 Comment

Posted by on April 8, 2011 in Uncategorized

 

Tags: ,

One response to “Suma numerelor impare

  1. UNUALTU

    April 8, 2012 at 12:46

    Mersi pe asta l-am inteles

     

Lasă un comentariu

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: