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 is linear search?
Why do we use return in c?
Write a program to swap two numbers without using third variable?
What are local static variables? How can you use them?
A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles
Write the syntax and purpose of a switch statement in C.
Explain what are compound statements?
Why do we write return 0 in c?
Can we change the value of static variable in c?
What is wrong with this program statement? void = 10;
write a c program for swapping two strings using pointer
Apart from dennis ritchie who the other person who contributed in design of c language.
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
Explain about the functions strcat() and strcmp()?
Are negative numbers true in c?