In this tutorial, we will discuss a concept of use of C program to find the sum of two numbers using recursion
In this article, we are going to learn how to calculate the addition of two numbers using recursion in the C programming language
Program
This program allows the entry of two digits from the user and to find the sum of two numbers using the recursive function in C programming language
#include <stdio.h> #include <stdlib.h> int add(int,int); //Function prototype int main() { int x,y,result; //variable declaration printf("enter two numbers: "); scanf("%d %d",&x,&y); result=add(x,y);//function call printf("Sum of two numbers are: %d\n",result); getch(); return 0; } int add(int x, int y) //function declaration(recursive function) { if(y==0) return x; else return(1+add(x,y-1)); }
When the above code is executed, it produces the following results
Enter two numbers: 23 34 sum of two numbers are:57
Method
Similar post
C code to the sum of two numbers
C program to sum of two numbers using the function
C program to calculate sum of array elements
Suggested for you
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…
View Comments
When we take both values negative then this code is not worked.
Eg x=-4,y=-4