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 || 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 ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

3493


write a program using linked list in which each node consists of following information. Name[30] Branch Rollno Telephone no i) Write the program to add information of students in linked list

2225


Why we use stdio h in c?

570


What should malloc() do?

632


the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset

631






What do you understand by friend-functions? How are they used?

633


What is the difference between a string and an array?

699


Why does not c have an exponentiation operator?

620


What is the symbol indicated the c-preprocessor?

686


What is the use of the function in c?

591


What is the -> in c?

571


Why is c called a structured programming language?

664


please give me some tips for the placement in the TCS.

1622


Is fortran faster than c?

570


Can we use any name in place of argv and argc as command line arguments?

602