Q.11 Generate the following pattern using code in any
language(c/c++/java) for n no. of rows
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Answer Posted / balaji ganesh
main()
{
int a[20][20],i,j,n;
clrscr();
a[0][0]=1;
scanf("%d",&n,printf("enter how many rows you want:"));
for(i=0;i<n;i++)
{a[i][0]=1;a[i][i]=1;
for(j=1;j<i;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
for(i=0;i<n;i++)
{printf("\n\n");
for(j=0;j<=i;j++)
printf("%d ",a[i][j]);
}
getch();
}
| Is This Answer Correct ? | 6 Yes | 3 No |
Post New Answer View All Answers
Why c is procedure oriented?
How to delete a node from linked list w/o using collectons?
using for loop sum 2 number of any 4 digit number in c language
What is the difference between malloc() and calloc() function in c language?
What is the purpose of void in c?
Why do we use pointer to pointer in c?
What is void c?
What does %c mean in c?
What is a constant and types of constants in c?
What is a program flowchart and how does it help in writing a program?
How can I implement a delay, or time a users response, with sub-second resolution?
which is conditional construct a) if statement b) switch statement c) while/for d) goto
When should you use a type cast?
What are different types of variables in c?
Subtract Two Number Without Using Subtraction Operator