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
How was c created?
How can I delete a file?
write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1
a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler
Calculate the weighted average of a list of n numbers using the formula xavg = f1x1+f2x2+ ….+ fnxn where the f’s are fractional weighting factors, i.e., 0<=fi<1, and f1+f2+….+fn = 1
What are the applications of c language?
What is scope and lifetime of a variable in c?
What is 1f in c?
What is the difference between formatted&unformatted i/o functions?
How can I call fortran?
What is difference between scanf and gets?
What are the types of functions in c?
Which driver is a pure java driver
What does & mean in scanf?
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..