Posts

Showing posts from October 4, 2012

REVERSE A NUMBER USING RECURSION

LIST OF PROGRAMS
#include<stdio.h>
#include<conio.h>
void main()
{
void t(int n2);
int n;
clrscr();
printf("ENTER A NUMBERS\n");
scanf("%d",&n);
printf("REVERSE NUMBER IS :\n");
t(n);
getch();
}
void  t(int n2)
{
if(n2<=0)
printf("\nTHANK YOU");
else
{ printf("%d",n2%10);
 t(n2/10);
}
}
LIST OF PROGRAMS

RETURN M TO THE POWER N USING RECURSION

LIST OF PROGRAMS
#include<stdio.h>
#include<conio.h>
void main()
{
int t(int m2,int n2);
int m,n;
clrscr();
printf("ENTER TWO NUMBERS\n");
scanf("%d%d",&m,&n);
printf("SOLUTION IS :\n");
printf("%d",t(m,n));
getch();
}
int  t(int m2,int n2)
{
if(n2<=0)
return(1);
else if(n2==1)
return(m2);
else
return(m2*t(m2,--n2));
}

LIST OF PROGRAMS

PRINT TABLE OF A NUMBER USING RECURSION

LIST OF PROGRAMS
#include<stdio.h>
#include<conio.h>
void main()
{
void t(int n2,int i2);
int n,i=1;
clrscr();
printf("ENTER A NUMBER");
scanf("%d",&n);
printf("TABLE IS :\n");
t(n,i);
getch();
}
void  t(int n2,int i2)
{
  if(i2>10)
  {
  printf("thank you");
  }
  else
  {
printf("\t %d * %d = %d\n",n2,i2,n2*i2 );
    i2++;
    t(n2,i2);
  }
}
LIST OF PROGRAMS

FACTORIAL USING RECURSION

LIST OF PROGRAMS
#include<stdio.h>
#include<conio.h>
void main()
{
int fact(int n2);
int f,n;
clrscr();
printf("ENTER A NUMBER");
scanf("%d",&n);
f=fact(n);
printf("FACTORIAL %d",f);
getch();
}
int fact(int n2)
{
if(n2<0)
return(0);
else if (n2==0||n2==1)
return(1);
else
return(n2*fact(n2-1));
}


LIST OF PROGRAMS