x^y using recursion

Program:

#include<stdio.h>
int power(int a,int b);
int main()
{
int x,y,ans;
printf("Enter x and y:\n ");
scanf("%d %d",&x,&y);
ans=power(x,y);
printf("%d^%d= %d",x,y,ans);
 return 0;
}
int power(int a,int b)
{
if(b==0)
{
return 1;
}
else
{
return a*power(a,b-1);
}
}

Output:



Fibbonacci series using recursion

Program:

#include<stdio.h>
int fibbonacci(int n);
int main()
{
int i,n;
printf("Enter no. of elements: ");
scanf("%d",&n);
 printf("Fibbonacci of %d:\n " , n);
for(i=0;i<n;i++)
{
      printf("%d ",fibbonacci(i));         
 }
    return 0;
}
int fibbonacci(int n)
{
   if(n == 0)
   {
      return 0;
   }
   else if(n == 1)
   {
      return 1;
   }
   else
   {
      return (fibbonacci(n-1) + fibbonacci(n-2));
   }
}

Output:



Factorial program using recursion

Program:

#include<stdio.h>
long int fact(int n);
int main()
{
int m;
long int f;
printf("Enter Number: ");
scanf("%d",&m);
f=fact(m);
printf("Factorial of %d is : %ld",m,f);
    return 0;
}
long int fact(int n)
{
if(n==1)
{
return 1;
}
else
{
return n*fact(n-1);
}
}

Output:





Reverse string using function

Program:

#include<stdio.h>
#include<string.h>
void reverse(char s[]);
int main()
{
char str[100];
printf("Enter a string: ");
scanf("%s",str);
reverse(str);
printf("%s",str);
    return 0;
}
void reverse(char s[])
{
  int i,j;
  char temp;
  for(i=0,j=strlen(s)-1;i<strlen(s)/2;i++,j--)
  {
  temp=s[i];
  s[i]=s[j];
  s[j]=temp;
  }
}

Output:



Maximum no. from array elements using function

Program:

#include<stdio.h>
int max(int m[],int n);
int main()
{
int a[10],n,i;
printf("Enter No. of elements: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
    printf("Maximum: %d",max(a,n));
    return 0;
}
int max(int m[],int n)
{
  int max=0,i;
  for(i=0;i<n;i++)
  {
  if(m[i]>max)
  {
         max=m[i];
}
  }
  return max;
}

Output:



x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...