Give me an integer and I will sum it with the previous natural numbers

How to write a C Program Give me an integer and I will sum it with the previous natural numbers in C Programming Language ?

This C Program Change an Integer Number with Addition of Previous Natural Numbers.
 
Solution:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int geometric_sum (int a);
  4. int main ()
  5. {
  6.     int a = 0, sum = 0;
  7.     printf("Give me an integer and I will sum it with the previous natural numbers : ");
  8.     scanf("%d", &a);
  9.     sum = geometric_sum(a);
  10.     printf("Result: %d", sum);
  11. }
  12.  
  13. int geometric_sum (int a)
  14. {
  15.     if (== 0)
  16.     {
  17.         printf("Base case!\n");
  18.         return a;
  19.     }
  20.  
  21.     else
  22.     {
  23.         printf("1: sum (%d)\n", a);
  24.         return a + geometric_sum(a-1);
  25.     }
  26.  
  27. }


Learn More :