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
Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......
write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.
What is c language & why it is used?
What does typeof return in c?
What is main function in c?
What are the properties of union in c?
how to write optimum code to divide a 50 digit number with a 25 digit number??
How can I find the modification date and time of a file?
What are the usage of pointer in c?
What are global variables and how do you declare them?
difference between Low, Middle, High Level languages in c ?
Describe the steps to insert data into a singly linked list.
What is the explanation for modular programming?
what are the facialities provided by you after the selection of the student.
Write a program to find factorial of a number using recursive function.