/*Program to print the element of pascal-triangle when the row and column numbers are given.\
pascal triangle:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
................................
......................................
*/
#include<stdio.h>
int pascal(int a,int b)
{
if (a==b)
return 1;
else if (b==1)
return 1;
else
return pascal(a-1,b-1)+pascal(a-1,b);
}
int main()
{
int a,b;
printf("Enter row number : ");
scanf("%d",&a);
printf("Enter column\n number : ");
scanf("%d",&b);
if ( (b>a) || (b<=0) || (a<=0) )
printf("Invalid Entry\n");
else
printf("The (%d,%d)th element of pascal triangle is : %d\n",b,a,pascal(a,b));
return 0;
}
pascal triangle:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
................................
......................................
*/
#include<stdio.h>
int pascal(int a,int b)
{
if (a==b)
return 1;
else if (b==1)
return 1;
else
return pascal(a-1,b-1)+pascal(a-1,b);
}
int main()
{
int a,b;
printf("Enter row number : ");
scanf("%d",&a);
printf("Enter column\n number : ");
scanf("%d",&b);
if ( (b>a) || (b<=0) || (a<=0) )
printf("Invalid Entry\n");
else
printf("The (%d,%d)th element of pascal triangle is : %d\n",b,a,pascal(a,b));
return 0;
}
No comments:
Post a Comment