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 pragma directive in c?

917


What is the purpose of main( ) in c language?

923


What is the value of c?

816


What is auto keyword in c?

993


What is output redirection?

936


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)

2123


Can you write the algorithm for Queue?

1790


Which control loop is recommended if you have to execute set of statements for fixed number of times?

1119


What are terms in math?

821


What is a header file?

860


How to write c functions that modify head pointer of a linked list?

770


What are the string functions? List some string functions available in c.

829


Where is volatile variable stored?

872


Where are some collections of useful code fragments and examples?

971


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

1869