C Program to Add Two Numbers Using Recursion



Recursion is a programming technique that allows the programmer to express operations in terms of themselves. In C, this takes the form of a function that calls itself.



  1. //C program to add two numbers using recursion
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. int add(int,int);
  5. int main()
  6. {
  7. int a,b,r;
  8. printf("enter two numbers: ");
  9. scanf("%d %d",&a,&b); //taking input
  10. result=add(a,b); //calling the recursive function
  11. printf("Sum of two numbers are: %d\n",result); //output
  12. getch();
  13. return 0;
  14. }
  15. int add(int a,int b) //recursive function
  16. {
  17. if(y==0)
  18. return a;
  19. else
  20. return(1+add(a,b-1));
  21. }

Output
Output!
download android app

Popular C Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube