C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf
FIND POWER OF A NUMBER USING RECURSION USING C PROGRAM
Sum of n numbers using recursion in c
Matrix multiplication using recursion in c
Multiplication using recursion in c
Lcm using recursion in c
Using recursion in c find the largest element in an array
Prime number program in c using recursion
Decimal to binary conversion in c using recursion
C program for fibonacci series using recursion
Reverse a string using recursion
Write a program for palindrome using recursion
Find factorial of a number using recursion in c program
Find gcd of a number using recursion in c program
Find sum of digits of a number using recursion using cprogram
Find power of a number using recursion using c program
Binary search through recurssion using c program
Reverse a number using recursion in c program
Big list of c program examples
Subscribe to:
Post Comments (Atom)
16 comments:
thank u very much
it does not works for power(10,6)...why?
it's working for (10,6) also once check it....
can you help me with this one? program that will print out
powers of 2: 1, 2, 4, 8, .. up to 2n, where n is a user input.
It Does n't work
this power function is not efficient...
modify like this>>>>>>>
A better recursion function for power calculation...
pow(int a,int b)
{
if(b==0)
return 1;
if(b%2==0)
return pow(a*a,b/2);
return pow(a*a,b/2)*a;
}
good job
Yr what is this? It is not working. Make it right, otherwise my girlfriend will kill me. do it fast. Tomorrow will b her practicals, I am management student. Did not know what the hell are you doing with this C
try this ....this code surely works :) chancahl tripathi:)
#include
#include
int power(int x,int p);
void main()
{
int n,p;
clrscr();
printf("enter no.and power");
scanf("%d%d",&n,&p);
printf("%d",power(n,p));
getch();
}
int power(int x,int p)
{
if(p==0)
return 1;
else
return (x*power(x,p-1));
}
awesome.
#include
#include
#include
int power(int,int,int);
main()
{
int num,i=1,p,result;
printf("Enter a number:");
scanf("%d",&num);
printf("Enter power:");
scanf("%d",&p);
result=power(num,i,p);
printf("\n%d to the power of %d is: %d",num,p,result);
getch();
}
int power(int num,int i,int p)
{
if(i==p)
{
return pow(num,i);
}
else
{
return power(num,i+1,p);
}
}
#include
#include
unsigned int Number_a_to_number_b(unsigned int a, unsigned int b);
unsigned int x,y;
unsigned int answer=0;
int main()
{
printf("Enter a base");
scanf("%u",&x );
printf("Enter a power");
scanf("%u",&y);
answer = Number_a_to_number_b(x,y);
printf("%u to power %u is %u",x,y,answer);
return 0;
}
unsigned int Number_a_to_number_b(unsigned int a, unsigned int b)
{
if (b==0)
return 1;
if (b==1)
return a;
//answer*=a;
return a*Number_a_to_number_b(a,(b-1));
}
(i=1;i<=Thenumberyouinput;i++);
Answer=i*2
try it
this program much better this
#include
int power(int a,int b);
main()
{
int a,out;
int b;
printf("Enter Power :");
scanf("%d",&a);
printf("Enter base");
scanf("%d",&b);
out= power(a,b);
printf("power=%d",out);
getch();
}
int power(int x, int y)
{
int i,t=1;
for(i=1;i<=y;i++)
{
t=t*x;
}
return t;
}
(Easy way for power)
#include
void main()
{
int base,index,pow=1;
printf("\n Enter the Base : ");
scanf("%d",&base);
printf("\n Enter the Index : ");
scanf("%d",&index);
for(int i=1;i<=y;i++)
{
pow=pow*base;
}
printf("\n %d^%d = %d",base,index,pow);
}
(Easy way fo power)
#include
void main()
{
int base,index,pow=1;
printf(" Enter the Base : ");
scanf("%d",&base);
printf(" Enter the Index : ");
scanf("%d",&index);
for(int i=1;i<=index;i++)
{
pow=pow*base;
}
printf("%d^%d=%d",base,index,pow);
}
Post a Comment