C Online Compiler
Example: Sum of Two Numbers in C using Recursion
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Sum of Two Numbers in C using Recursion #include <stdio.h> int sum; // This function will return sum of two integer numbers int Sum(int a, int b) { if (b == 0) return a; // Recursion: adding 1, N times and, then at the end adding m to it sum = Sum(a, b - 1) + 1; return sum; } // It's the driver function int main() { int p, q; printf("Enter two integer values::\n"); scanf("%d %d", &p, &q); printf("Result:: %d + %d = %d\n", p, q, Sum(p, q)); return 0; }
10 99
Output
Clear
ADVERTISEMENTS