2014-07-18T15:29:46-04:00
Write a C-program that asks the user to type an integer N for finding the sum of the
numbers 2, 4, 6, 8, …, n
1
2014-07-22T10:03:22-0400
#include <iostream> int calculateSum(int *arr, int size) { int sum = 0; for(int i = 0; i < size; ++i) sum += arr[i]; return sum; } int main() { int size; std::cout << "Enter size: " << std::endl; std::cin >> size; size /= 2; int *arr = new int[size]; for(int i = 0; i < size; ++i) { arr[i] = (i + 1) * 2; } std::cout << "Sum: " << calculateSum(arr, size) << std::endl; std::cin.get(); return 0; }
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS !
Learn more about our help with Assignments:
C++
Comments