944,196 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 28056
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
May 16th, 2005
0

Need Help With Printing Pascal's Triangle In C

Expand Post »
hi my name is srikanth.i have been trying to develop a source code to print the pascal's triangle for the past three days.i have'nt had any success.i would be greatly obliged if anyone could give me a simple source code to print the pascal's triangle in C.
Similar Threads
Reputation Points: 9
Solved Threads: 1
Junior Poster in Training
indianscorpion2 is offline Offline
82 posts
since May 2005
May 16th, 2005
0

Re: Need Help With Printing Pascal's Triangle In C

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.
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
May 16th, 2005
0

need a source code in C to print pascal's triangle

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.
Reputation Points: 9
Solved Threads: 1
Junior Poster in Training
indianscorpion2 is offline Offline
82 posts
since May 2005
May 16th, 2005
0

Re: need a source code in C to print pascal's triangle

You didn't like the answer the first time so you post it again?
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
May 18th, 2005
0

i need an algorithm to print pascal's triangle

i am a student of computer science.i require an algorithm to print the pascal's triangle.
Reputation Points: 9
Solved Threads: 1
Junior Poster in Training
indianscorpion2 is offline Offline
82 posts
since May 2005
May 18th, 2005
0

Re: Need Help With Printing Pascal's Triangle In C

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?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
May 18th, 2005
0

Re: Need Help With Printing Pascal's Triangle In C

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.
  1. #include <iostream>
  2.  
  3. double factorial(double n)
  4. {
  5. return (n > 1) ? n * factorial(n - 1) : 1;
  6. }
  7.  
  8. double ncr(int n, int r)
  9. {
  10. return factorial(n) / (factorial(r) * factorial(n - r));
  11. }
  12.  
  13. int main()
  14. {
  15. std::cout.setf(std::ios::fixed, std::ios::floatfield);
  16. std::cout.precision(0);
  17.  
  18. for (int i = 0; i < 15; i++) {
  19. for (int j = 0; j <= i; j++)
  20. std::cout << std::right << ncr(i, j) << ' ';
  21. std::cout << std::endl;
  22. }
  23. }
Reputation Points: 35
Solved Threads: 3
Posting Whiz in Training
Dogtree is offline Offline
232 posts
since May 2005
Jul 28th, 2005
0

Re: need a source code in C to print pascal's triangle

Quote 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.
  1. #include<stdio.h>
  2. void main()
  3. {
  4. int ary[i][j],n;
  5.  
  6. printf("\nEnter the number of rows:");
  7. scanf("%d",&n);
  8.  
  9. for(i=0;i<n;i++)
  10. {
  11. for(j=0;j<=i;j++)
  12. {
  13. if(j==0!!j==1)
  14. ary[i][j]=1;
  15. else
  16. ary[i][j]=ary[i-1][j-1]+ary[i-1][j];
  17. }
  18. }
  19.  
  20. for(i=0;i<n;i++)
  21. {
  22. printf("\n");
  23. for(j=0;j<=i;j++)
  24. {
  25. printf("%d",ary[i][j]);
  26. }
  27. }
  28. }
<< moderator edit: added [code][/code] tags >>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
uzone24 is offline Offline
3 posts
since Jul 2005
Jul 28th, 2005
0

Re: Need Help With Printing Pascal's Triangle In C

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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jul 29th, 2005
0

Re: Need Help With Printing Pascal's Triangle In C

Quote 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.
Narue can u elaborate on reasons y my code sucks as well wud fail ??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
uzone24 is offline Offline
3 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C Forum Timeline: frequency problem,can u plz do the documentation for mi
Next Thread in C Forum Timeline: Frequency of characters entered.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC