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

Question: We would like to design and implement a programming solution to the reader-writer problem using semaphores in C language under UNIX. We assume that we have three readers and two writers processes that would run concurrently. A writer is to update (write) into one memory location (let’s say a variable of type integer named temp initialized to 0). In the other hand, a reader is to read the content of temp and display its content on the screen in a formatted output. One writer can access the shared data exclusively without the presence of other writer or any reader, whereas, a reader may access the shared memory for reading with the presence of other readers (but not writers).

1 Answers  


could you please send the program code for multiplying sparse matrix in c????

0 Answers  


main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit >> (i - (i -1))); } } a. 512, 256, 0, 0, 0 b. 256, 256, 0, 0, 0 c. 512, 512, 512, 512, 512 d. 256, 256, 256, 256, 256

2 Answers   HCL,


int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p

2 Answers  


main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }

2 Answers   CSS, Wipro,






1 o 1 1 0 1 0 1 0 1 1 0 1 0 1 how to design this function format in c-language ?

2 Answers  


What is full form of PEPSI

0 Answers  


void main() { int i=i++,j=j++,k=k++; printf(“%d%d%d”,i,j,k); }

1 Answers  


main() { int i=10,j=20; j = i, j?(i,j)?i:j:j; printf("%d %d",i,j); }

2 Answers   Adobe, CSC,


main() { 41printf("%p",main); }8

1 Answers  


main() { int a[10]; printf("%d",*a+1-*a+3); }

1 Answers  


What is the subtle error in the following code segment? void fun(int n, int arr[]) { int *p=0; int i=0; while(i++<n) p = &arr[i]; *p = 0; }

1 Answers  


Categories