find A^B using Recursive function
Answers were Sorted based on User's Feedback
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 |
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 |
How we will connect multiple client ? (without using fork,thread)
main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }
int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().
main() { int i=0; while(+(+i--)!=0) i-=i++; printf("%d",i); }
9 Answers CSC, GoDB Tech, IBM,
There is a lucky draw held every day. if there is a winning number eg 1876,then all possible numbers like 1867,1687,1768 etc are the numbers that match irrespective of the position of the digit. Thus all these numbers qualify fr the lucky draw prize Assume there is no zero digit in any numbers. write a program to show all the possible winning numbers if a "winning number"is passed as an arguments to the function.
main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }
void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(“%d”, i); }
#define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort()) void main() { int i = 10; if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro"); }
int DIM(int array[]) { return sizeof(array)/sizeof(int ); } main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr)); }
main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }
In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'. main(){ int * j; void fun(int **); fun(&j); } void fun(int **k) { int a =0; /* add a stmt here*/ }
main() { int x=5; clrscr(); for(;x<= 0;x--) { printf("x=%d ", x--); } } a. 5, 3, 1 b. 5, 2, 1, c. 5, 3, 1, -1, 3 d. –3, -1, 1, 3, 5