Recursion is the process of repeating items in a self-similar way.
#include<stdio.h>
#include<conio.h>
main()
{
int n,m,x,bino;
clrscr();
printf("\n enter the value of n: ");
scanf("%d",&n);
printf("m/x");
for(m=0;m<=n;m++)
printf("%5d",m); // print in horz.
printf("\n---------------------------------------------------------\n");
m=0;
do{
printf("%2d",m); // print for vertical
x=0;
bino=1;
while(x<=m)
{
if((m==0)||(x==0))
printf("%5d",bino);
else
{
bino=bino*(m-x+1)/x; // calculate C(m,r)
printf("%5d",bino);
}
x=x+1;
}
printf("\n");
m=m+1;
}while(m<=n);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int n,m,x,bino;
clrscr();
printf("\n enter the value of n: ");
scanf("%d",&n);
printf("m/x");
for(m=0;m<=n;m++)
printf("%5d",m); // print in horz.
printf("\n---------------------------------------------------------\n");
m=0;
do{
printf("%2d",m); // print for vertical
x=0;
bino=1;
while(x<=m)
{
if((m==0)||(x==0))
printf("%5d",bino);
else
{
bino=bino*(m-x+1)/x; // calculate C(m,r)
printf("%5d",bino);
}
x=x+1;
}
printf("\n");
m=m+1;
}while(m<=n);
getch();
}
No comments:
Post a Comment