RSS

Suma numerelor pare

08 Apr

Am scris în Dev-C++ un algoritm care calculează suma primelor  n numere pare, unde n este un număr introdus de la tastatură. De exemplu, dacă n = 5 atunci suma = 2+4+6+8+10 = 30.

#include<iostream.h>
#include<conio.h>
int main()
{ int n,i,contor=0,suma=0;
 cout<<"n="; cin>>n;
 i=2;
 while(contor!=n)
 { suma=suma+i;
 i=i+2;
 contor++; }
 cout<<"Suma primelor "<<n<<" numere pare este: "<<suma;
 getch(); }
 
Leave a comment

Posted by on April 8, 2011 in Uncategorized

 

Tags: , ,

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: