find A^B using Recursive function

Answers were Sorted based on User's Feedback



find A^B using Recursive function..

Answer / addu

#include<stdio.h>
double pow(int,int);

main()
{
int m,n;
double res;
printf("Enter the number and the power : ");
scanf("%d%d",&m,&n);
res=pow(m,n);
printf("\nThe result is = %d\n",res);
}
pow(int m,int n)
{
if(n>0)
{
return m* pow(m,n-1);
} else if (n==0){
return 1;
} else {
return (1/((double)m))*pow(m,n+1);
)
}

Is This Answer Correct ?    5 Yes 2 No

find A^B using Recursive function..

Answer / nagarajanselvaraj

#include<stdio.h>
int pow(int,int);
int r=1;
main()
{
int m,n,res;
printf("Enter the number and the power : ");
scanf("%d%d",&m,&n);
res=pow(m,n);
printf("\nThe result is = %d\n",res);
}
pow(int m,int n)
{
if(n>0)
{
r=r*m;
n--;
pow(m,n);
}
return r;
}

Is This Answer Correct ?    4 Yes 2 No

Post New Answer

More C Code Interview Questions

Write a Program that Inputs 10 Numbers in an Array and Show the Maximum Number

2 Answers   Ace Info,


#define a 10 void foo() { #undef a #define a 50 } int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } explain the answer

1 Answers  


Is it possible to type a name in command line without ant quotes?

1 Answers   Excel, Infosys,


#define prod(a,b) a*b main() { int x=3,y=4; printf("%d",prod(x+2,y-1)); }

1 Answers  


Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };

1 Answers  






why nlogn is the lower limit of any sort algorithm?

0 Answers  


# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }

1 Answers  


#define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); }

3 Answers  


main(int argc, char **argv) { printf("enter the character"); getchar(); sum(argv[1],argv[2]); } sum(num1,num2) int num1,num2; { return num1+num2; }

1 Answers  


# include<stdio.h> aaa() { printf("hi"); } bbb(){ printf("hello"); } ccc(){ printf("bye"); } main() { int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[2](); }

1 Answers  


main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }

1 Answers  


C statement to copy a string without using loop and library function..

2 Answers   Persistent, TCS,


Categories