TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C Program To Print Pascal Triangle
Shobana J
Jul 29, 2016
191.5
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog, you will learn how to print Pascal triangle.
pscl.zip
Introduction
In this blog, I am going to explain how to print a Pascal triangle.
Software Requirements
Turbo C++ or C.
Programming
#include < stdio.h >
long
factorial(
int
);
int
main()
{
int
i, n, c;
printf(
"Enter the number of rows you wish to see in pascal triangle\n"
);
scanf(
"%d"
, & n);
for
(i = 0; i < n; i++) {
for
(c = 0; c <= (n - i - 2); c++) printf(
" "
);
for
(c = 0; c <= i; c++) printf(
"%ld "
, factorial(i) / (factorial(c) * factorial(i - c)));
printf(
"\n"
);
}
return
0;
}
long
factorial(
int
n) {
int
c;
long
result = 1;
for
(c = 1; c <= n; c++) result = result * c;
return
result;
}
Explanation
With the help of programming given above, Pascal triangle can be printed by giving the number of rows by the user.
Output
C Program
Pascal Triangle
Next Recommended Reading
Print Alternate Elements In An Array