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
Explain how do you declare an array that will hold more than 64kb of data?
How can I make sure that my program is the only one accessing a file?
What is oops c?
Explain how can type-insensitive macros be created?
Define macros.
What is array of structure in c?
What are linker error?
Difference between macros and inline functions? Can a function be forced as inline?
what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;
Define C in your own Language.
What tq means in chat?
A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?
What is property type c?
Is register a keyword in c?
Describe explain how arrays can be passed to a user defined function