c++program (code only)

a program that adds the following numbers
5+10+15+20+25.....+n
5+10=15
5+10+15=25
5+10+15=25

30?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
int add_by5(int num);

int main () {
	int num = 0;
	cout << "Enter the number of times you with to run"<<endl;
	cin >> num;
	cout << add_by5(num);
	return 0;
}

int add_by5(int num){
	int sum = 0;
	for (int i = 1; i < num ; i++) {
		sum += (num*5);
	}
	return sum;
}

This will add increase the running sum by 5 for 'n' iterations
so say you enter in 3, the sum will = 30
i.e 5+10+15= 30
Last edited on
Topic archived. No new replies allowed.