What does this code do? Why does it have two return values?
int MSum(int N){
if (N == 1)
return 1;
return N + MSum(N - 1);
}
I tried writting the phollowing program to run it. It compiles fine, but I get error when I run it:
#include <stdio.h>
int MSum(int N);
int main(){
int n, o;
printf("Εισάγετε ακέραιο: ");
scanf("%d", &n);
o = MSum(n);
printf("%d", o);
return 0;
}
int MSum(int N){
if (N == 1)
return 1;
return N + MSum(N - 1);
}
The error I get is:
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status