0
I need to make a program with a recursive function that takes two integers as parameters n
and m
, where n <= m
and returns the sum of the numbers in this range.
For example, if n = 1
and m = 4
then the result would be 10
: 1 + 2 + 3 + 4
.
But I need help being a beginner in programming.
I came to make the following code:
#include <iostream>
using namespace std;
int somanm(int n,int m){
int s = 1;
for(int i = 1; i <= m; i++ )
s = (i(i+1))/2;
return s;
}
int main(){
int n, m, s, resul;
cin >> n >> m;
resul = somanm(n,m);
cout << resul;
}