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
What is an array in c?
Do pointers need to be initialized?
Why is c fast?
Why should I use standard library functions instead of writing my own?
A routine usually part of the operation system that loads a program into memory prior to execution a) linker b) loader c) preprocessor d) compiler
What is strcpy() function?
What is the hardest programming language?
What is call by value in c?
How is a pointer variable declared?
What are the key features in c programming language?
What is sizeof int in c?
What is ponter?
What is indirection? How many levels of pointers can you have?
What is the use of extern in c?
What is the meaning of c in c language?