This C Program generates pascal triangle 1 dimensional array.
Here is source code of the C Program to generate pascal triangle 1 dimensional array. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Generate Pascal Triangle 1 D Array
*/
#include <stdio.h>
void main()
{
int array[30], temp[30], i, j, k, l, num; //using 2 arrays
printf("Enter the number of lines to be printed: ");
scanf("%d", &num);
temp[0] = 1;
array[0] = 1;
for (j = 0; j < num; j++)
printf(" ");
printf(" 1\n");
for (i = 1; i < num; i++)
{
for (j = 0; j < i; j++)
printf(" ");
for (k = 1; k < num; k++)
{
array[k] = temp[k - 1] + temp[k];
}
array[i] = 1;
for (l = 0; l <= i; l++)
{
printf("%3d", array[l]);
temp[l] = array[l];
}
printf("\n");
}
}
$ cc pgm69.c $ a.out Enter the number of lines to be printed: 4 1 1 1 1 2 1 1 3 3 1
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
If you wish to look at other example programs on Arrays, go to C Programming Examples on Arrays. If you wish to look at programming examples on all topics, go to C Programming Examples.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Watch Advanced C Programming Videos
- Check C Books
- Apply for C Internship
- Practice BCA MCQs
- Check Computer Science Books