Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- cout << "Program to calculate the sum from of even numbers from 1 to n\n";
- cout << "-------------------------------------------------------------\n";
- cout << "Enter n: ";
- int n;
- cin >> n;
- int ans = 0;
- for (int i = 2; i <= n; i += 2)
- {
- ans += i;
- }
- cout << "The sum of even numbers from 1 to " << n << " is: " << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment