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
p*=(++q)++*--p when p=q=1 while(q<=6)
What is keyword with example?
Explain 'bit masking'?
Describe the modifier in c?
Explain what are compound statements?
What are the 4 types of functions?
process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,
Explain the Difference between the New and Malloc keyword.
Difference between strcpy() and memcpy() function?
find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }
How pointer is different from array?
Write a program to print all permutations of a given string.
Why isn't any of this standardized in c? Any real program has to do some of these things.
How many levels of pointers can you have?
What is uint8 in c?