Chapter - 6: Functions And Pointers

Write a recursive function to obtain the running sum of the first 25 natural numbers.


G
Sections
7
Exercises

A

B

C

D

E

F

G

1

2

3

4

5

6

7

8

9

10

11

12

#include<stdio.h>
#include<conio.h>

int sum(int);

int main()
{
	int ans = sum(25);
	printf("Running sum of the numbers : %d", ans);
	_getch();
	return 0;
}

int sum(int x)
{
	if (x == 0)
		return x;
	x = x + sum(x - 1);
	return x;
}

© 2020 Garbage Valuegarbage value logo