write a program that prints a pascal triangle based on the
user input(like how many stages) in an efficient time and
optimized code?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / 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 |
Answer / abhinav
call this recursive routine:
void pascal(int n)
{
if(n==1) {
printf("%d \n", n);
return;
}
pascal(n-1);
int i;
for(i=1;i<=n; i++)
printf("%d ",i);
for(i=n-1;i>=1; i--)
printf("%d ",i);
printf("\n");
}
Is This Answer Correct ? | 0 Yes | 0 No |
logic for generating all the combinations of the any number of given letters. ex::::::::: if a,b,c,d are given the o/p should be abcd,dcba,dbac,bcad,................ 4*3*2*1 combinations............
What is signed and unsigned?
Explain Doubly Linked Lists?
What are different types of pointers?
WHAT IS MEANT BY LIFE?
Why is void main used?
write a program to compare 2 numbers without using logical operators?
Is c procedural or object oriented?
What is f'n in math?
What is a nested loop?
can we define a function in structure?
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }