Created
June 10, 2018 14:07
-
-
Save ashwanthkumar/b9dce4ebf19816d71574bc81e4eb83ef to your computer and use it in GitHub Desktop.
Sum of N numbers without mutating any variables.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int sum(int n) { | |
if (n == 1) return 1; | |
else return n + sum(n - 1); | |
} | |
int main() { | |
int input; | |
scanf("%d", &input); | |
const int s = sum(input); | |
printf("%d\n", s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment