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 do you mean by keywords in c?
What is 2c dna?
What is pointer to pointer in c language?
what do you mean by enumeration constant?
What is the correct code to have following output in c using nested for loop?
What is data structure in c programming?
What are the uses of null pointers?
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above
What is function in c with example?
What is the purpose of scanf() and printf() functions?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
What are the rules for the identifier?
Is using exit() the same as using return?
Why doesnt that code work?
which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above