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 || 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 |
Post New Answer View All Answers
How to write c functions that modify head pointer of a linked list?
i have to apply for rbi before that i need to know the the syllabus for the entrance questions. whethet it may be aps or techinical
Which header file should you include if you are to develop a function which can accept variable number of arguments?
Do string constants represent numerical values?
what do the 'c' and 'v' in argc and argv stand for?
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
write a c program for swapping two strings using pointer
Tell me with an example the self-referential structure?
what is the difference between class and unio?
What do you mean by a sequential access file?
List the different types of c tokens?
Explain the binary height balanced tree?
What is stack in c?
What tq means in chat?
write a program that will open the file, count the number of occurences of each word in the the complete works of shakespeare. You will then tabulate this information in another file.