Here is the code
#includeusing namespace std; int main() { int n; int sum = 0; int number; cout << "Enter the value for n: "; cin >> n; for (number=1; number<=(2*n); number+2) { sum = sum + number; } cout << "The sum of "; cout << n; cout << " is "; cout << sum << endl; return 0; }
Sunday, 3 April 2011
Write a program in C / C++ that calculate the summation of consecutive positive odd integers from 1 to n
Labels:
C Programs
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment