write a program that prints a pascal triangle based on the
user input(like how many stages) in an efficient time and
optimized code?

Answer Posted / vamsi krishna

#include<stdio.h>
#include<conio.h>
main()
{
int i,j,n;
clrscr();
printf("enter the highest power");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=0;j<(n-i);j++)
printf(" ");
for(j=0;j<=i;j++)
printf("%d ",c(i,j));
printf("\n");
}
getch();
}
c(int i,int j)
{
int k,N=1,D=1;
if(i==0)
return(1);
if(j==0)
return(1);
for(k=0;k<j;k++)
{
N=N*(i-k);
D=D*(j-k);
}
return(N/D);
}

Is This Answer Correct ?    7 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

p*=(++q)++*--p when p=q=1 while(q<=6)

1470


What is keyword with example?

819


Explain 'bit masking'?

835


Describe the modifier in c?

854


Explain what are compound statements?

803


What are the 4 types of functions?

779


process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,

2138


Explain the Difference between the New and Malloc keyword.

874


Difference between strcpy() and memcpy() function?

855


find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }

2053


How pointer is different from array?

810


Write a program to print all permutations of a given string.

918


Why isn't any of this standardized in c? Any real program has to do some of these things.

908


How many levels of pointers can you have?

923


What is uint8 in c?

869