•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 397,771 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,541 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 14161 | Replies: 14
![]() |
If you've been working on it for 3 days, surely you have developed a starting point. Why don't you post your code, indicate specifically what's not working, and someone will help you.
•
•
Join Date: May 2005
Posts: 80
Reputation:
Rep Power: 0
Solved Threads: 1
hi i am a student of computer science.i am a beginner.i am looking for a simple source code in C to print the pascal's triangle.the user should have the option to enter the number of rows he requires to view.i would be obliged if anyone could help out here.
•
•
Join Date: May 2005
Posts: 80
Reputation:
Rep Power: 0
Solved Threads: 1
i am a student of computer science.i require an algorithm to print the pascal's triangle.
Merged threads: indianscorpion2, please don't start new threads with the same topic in a relatively short period of time (a couple days). If you haven't had any success, how about starting with a failed attempt?
Here's the mathematical way to do it. But if this is homework, your teacher is probably looking for the brute force way of doing it. I won't show you that one because half the fun is figuring things out for yourself. The other half is writing the code to do it. 

#include <iostream>
double factorial(double n)
{
return (n > 1) ? n * factorial(n - 1) : 1;
}
double ncr(int n, int r)
{
return factorial(n) / (factorial(r) * factorial(n - r));
}
int main()
{
std::cout.setf(std::ios::fixed, std::ios::floatfield);
std::cout.precision(0);
for (int i = 0; i < 15; i++) {
for (int j = 0; j <= i; j++)
std::cout << std::right << ncr(i, j) << ' ';
std::cout << std::endl;
}
}•
•
Join Date: Jul 2005
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Originally Posted by indianscorpion2
hi i am a student of computer science.i am a beginner.i am looking for a simple source code in C to print the pascal's triangle.the user should have the option to enter the number of rows he requires to view.i would be obliged if anyone could help out here.
#include<stdio.h>
void main()
{
int ary[i][j],n;
printf("\nEnter the number of rows:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
if(j==0!!j==1)
ary[i][j]=1;
else
ary[i][j]=ary[i-1][j-1]+ary[i-1][j];
}
}
for(i=0;i<n;i++)
{
printf("\n");
for(j=0;j<=i;j++)
{
printf("%d",ary[i][j]);
}
}
} uzone24, one reason I haven't moderated your post is because the original question was posed several months ago. But we don't give answers to homework without effort on the student's part. The other reason is because your code both sucks and is horribly broken, so if someone bothered to turn it in, they would surely fail.
Member of: Beautiful Code Club.
•
•
Join Date: Jul 2005
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Originally Posted by Narue
uzone24, one reason I haven't moderated your post is because the original question was posed several months ago. But we don't give answers to homework without effort on the student's part. The other reason is because your code both sucks and is horribly broken, so if someone bothered to turn it in, they would surely fail.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
Similar Threads
Other Threads in the C Forum
- Previous Thread: frequency problem,can u plz do the documentation for mi
- Next Thread: Frequency of characters entered.


Linear Mode