Advertisement
AquaBlitz11

[t005] sum

Oct 9th, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.25 KB | None | 0 0
  1. #include<stdio.h>  
  2. long sum(long i)
  3. {
  4.     if(i==1)
  5.     {
  6.         return i;
  7.     }
  8.     else
  9.     {
  10.         return i+sum(i-1);
  11.     }
  12. }
  13. int main()
  14. {
  15.     long i;
  16.     scanf("%ld",&i);
  17.     printf("%ld",sum(i));
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement