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
What are all different types of pointers in c?
What is %d called in c?
What is the maximum length of an identifier?
What is the deal on sprintf_s return value?
Write a C++ program to generate 10 integer numbers between - 1000 and 1000, then store the summation of the odd positive numbers in variable call it sum_pos, then find the maximum digit in this variable regardless of its digits length.
a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above
Explain the difference between malloc() and calloc() in c?
How can you draw circles in C?
What is the advantage of an array over individual variables?
Differentiate between functions getch() and getche().
What are variables c?
Why clrscr is used after variable declaration?
how do you execute a c program in unix.
A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor
What is the meaning of typedef struct in c?