C Program to Find Sum of n Numbers Using Recursion

Hello Geeks! If you are interested to learn about “C Program to Find Sum of n Numbers Using Recursion” then read this article to learn about it. Let’s go for an article directly.

C Program to Find Sum of n Numbers Using Recursion

C Program to Find Sum of n Numbers Using Recursion

Source Code

#include <stdio.h>
long calculate_sum(int [], int);

int main()
{
  int n, c, array[100];
  long result;

  scanf("%d", &n);

  for (c = 0; c < n; c++)
    scanf("%d", &array[c]);

  result = calculate_sum(array, n);

  printf("Sum = %ldn", result);

  return 0;
}

long calculate_sum(int a[], int n) {
  static long sum = 0;

  if (n == 0)
    return sum;

  sum = sum + a[n-1];

  return calculate_sum(a, --n);
}

Final Thoughts

I hope this article helps you to know the concept “C Program to Find Sum of n Numbers Using Recursion” clearly. If you face any issues please let me know via the comment section. Share this article with other C/C++ developers via social networks. 

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment