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 |
Can you write the function prototype, definition and mention the other requirements.
How are variables declared in c?
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none
What is optimization in c?
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Explain the use of keyword 'register' with respect to variables.
What are the features of the c language?
Q.1 write a program to create binary tree 1 to 16 numbers? Q.2 write a program to creat a binary search tree for the member that is given by user?
int a=20; int b=30; int c=40; printf("%d%d%d"); what will be the output?
Is it better to use malloc() or calloc()?
n=7623 { temp=n/10; result=temp*10+ result; n=n/10 }
int i =10 main() { int i =20,n; for(n=0;n<=i;) { int i=10 i++; } printf("%d", i);