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


Please Help Members By Posting Answers For Below Questions

What is the function of multilevel pointer in c?

850


What are the 5 data types?

791


What are the different categories of functions in c?

886


program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)

1866


How can I run c program?

939


One of the Institutes contains 5 student groups. Every group contains 4 students. Institute wants to store student group’s details in array. Group should contain group member’s details (name and registration number and age), project name, and mark of the group.

2428


What are types of functions?

773


What is a pointer value and address in c?

829


4. main() { int c=- -2; printf("c=%d",c); }

1570


Explain what math functions are available for integers? For floating point?

859


What is pragma in c?

857


What are keywords in c with examples?

837


How arrays can be passed to a user defined function

789


Tell me when is a void pointer used?

871


What is a double c?

780