Write a C program to get the desired output.
1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
.
.
.
1 n..............n 1
Note: n is a positive integer entered by the user.
Answer Posted / sandip pal
#include<stdio.h>
#include<conio.h>
int ncr(int,int);
int fact(int);
void main()
{
int i,j;
clrscr();
for(i=0;i<=5;i++)
{
printf("\n\n");
for(j=0;j<=5-i;j++)
printf(" ");
for(j=0;j<=i;j++)
printf(" %2d ",ncr(i,j));
}
getch();
}
int ncr(int n,int r)
{
int f;
f=fact(n)/(fact(n-r)*fact(r));
return f;
}
int fact(int n)
{
if(n==0)
return 1;
else
n=n*fact(n-1);
return n;
}
Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
what is the function of pragma directive in c?
What is the purpose of main( ) in c language?
What is the value of c?
What is auto keyword in c?
What is output redirection?
pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice)
Can you write the algorithm for Queue?
Which control loop is recommended if you have to execute set of statements for fixed number of times?
What are terms in math?
What is a header file?
How to write c functions that modify head pointer of a linked list?
What are the string functions? List some string functions available in c.
Where is volatile variable stored?
Where are some collections of useful code fragments and examples?
a) Identify the following declarations. Ex. int i (integer variable) float a[l0](array of 10 real nos) int (*f())() void *f int (*f()) [] void *f int f[] [] [] char *(*f) () int (*f[]) [] float(*f) [] [] float **f int ******f