GoogelAddUnit1

Thursday, 10 March 2011

C Program to add two elements using recursion.


/*   adding two elements using recursion  */                                        
#include<stdio.h>
#include<conio.h>
main()
{
    int a,b,c;
    printf("\n enter the a,b values");
    scanf("%d%d",&a,&b);
    c=add(a,b);
    printf("\n %d",c);
    getch();
}
add(int a,int b)
{
   if(a==0)
     return(b);
   else
    return(add(--a,++b);
}

No comments:

Post a Comment