English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a program that reads in a positive integer N and calculates and displays the sum of the first N even integers. For example if N is 6, the program should display the value 42, which is: 2+4+6+8+10+12=42.

Caution: The program has to do the addition.

2007-12-26 09:08:05 · 1 answers · asked by Brandon P 1 in Computers & Internet Programming & Design

I've tried everything I can't get it to work.

2007-12-26 11:54:06 · update #1

1 answers

int n;
int sum = 0;
scanf("%d",&n);
for ( int i = 1; i <= n; ++i){
sum += i*2;
}
printf(sum);

2007-12-26 09:12:33 · answer #1 · answered by jgoulden 7 · 2 0

fedest.com, questions and answers