Write a recursive program to calculate ab where a and b are integers.

#include<stdio.h>

#include<math.h>

int main()

{

    int a,b,c;

    c=0;

    printf("Enter the numbers = ");

    scanf("%d %d",&a,&b);

    c=powRecurse(a,b);

    printf("%d power %d is = %d ",a,b,c);

}

powRecurse(int a,int b)

{

    if(b==0)

    {

        return 1;

    }

    if(b==1)

    {

        return a;

    }

    else

    {

        return a*powRecurse(a,b-1);

    }

}
Write a recursive program to calculate ab where a and b are integers. Write a recursive program to calculate ab  where a and b are  integers. Reviewed by Unknown on 03:40 Rating: 5

No comments:

Powered by Blogger.