943,832 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 5987
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 4th, 2007
0

pascal triangle?

Expand Post »
hi, nu member hir, just hav some question regarding this output:
  1. 1
  2. 232
  3. 34543
  4. 4567654
  5. 567898765
  6. 67890109876
  7. 7890123210987
  8. 890123454321098
  9. 90123456765432109
  10. 0123456789876543210
numbers that are alligned with 1 are

3
5
7
9
1
3
5
7
9

these are the middle numbers...

does anybody know how to do this in c language? or to look for its formula? tnx alot,,
Last edited by WaltP; Mar 5th, 2007 at 12:37 am. Reason: Try CODE tags -- that way explanations don't havfe to be confusing.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
stringgader is offline Offline
6 posts
since Mar 2007
Mar 4th, 2007
0

Re: pascal triangle?

Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,951 posts
since Aug 2005
Mar 5th, 2007
0

Re: pascal triangle?

does anybody know how to do this in c language? or to look for its formula? tnx alot,,
Yes, many of us know how to do this. The question is: do you? Or can you figure it out?

If you need help, asking specific questions and posting code you've tried will get excellent answers.
Moderator
Reputation Points: 3278
Solved Threads: 892
Posting Sage
WaltP is offline Offline
7,718 posts
since May 2006
Mar 5th, 2007
0

Re: pascal triangle?

no i cant, thats why im asking for someone hu can help me do thiis ,, its actually a problem,, twas given by our instructor and wants us to figure it out,, thats why ide like to gather any idea or information regarding this thing,,, tnx for the reply...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
stringgader is offline Offline
6 posts
since Mar 2007
Mar 5th, 2007
0

Re: pascal triangle?

by the way,, im only new to this programming thing,, tnx again
Reputation Points: 10
Solved Threads: 0
Newbie Poster
stringgader is offline Offline
6 posts
since Mar 2007
Mar 5th, 2007
1

Re: pascal triangle?

TRY THIS OUT

  1. #include<stdio.h>
  2. main()
  3. {
  4. int i,j,k;
  5. printf("\n");
  6. for(i=1;i<=10;i++)
  7. {
  8. for(j=1;j<=31-i;j++)printf(" ");
  9. for(j=i,k=(2*i-1)/2+1;k;j++,k--)
  10. {
  11. if(j==10)j=0;
  12. printf("%d",j);
  13. }
  14. for(j-=2,k=(2*i-1)/2;k;j--,k--)
  15. {
  16. if(j==-1)j=9;
  17. printf("%d",j);
  18. }
  19. printf("\n");
  20. }
  21. }
Last edited by ~s.o.s~; Mar 5th, 2007 at 12:07 pm. Reason: Added code tags, learn to use them.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
goutham_see is offline Offline
7 posts
since Feb 2007
Mar 5th, 2007
0

Re: pascal triangle?

TRY THIS OUT
goutham, around here we want the poster to find the answer. We help them with their code, we don't do their homework for them.


stringgader, read the above. In order to get this problem from your instructor, you must know something about code. This can't possibly be your first program.
by the way,, im only new to this programming thing,, tnx again
Duh, really?
Last edited by WaltP; Mar 5th, 2007 at 3:46 pm.
Moderator
Reputation Points: 3278
Solved Threads: 892
Posting Sage
WaltP is offline Offline
7,718 posts
since May 2006
Mar 5th, 2007
0

Re: pascal triangle?

no i cant, thats why im asking for someone hu can help me do thiis ,, its actually a problem,, twas given by our instructor and wants us to figure it out,, thats why ide like to gather any idea or information regarding this thing,,, tnx for the reply...
Go back and read the thread link that I posted, it contains the answer to your problem. If you don't understand the posted code to that thread then I doubt you are ready for the course you are taking. The proglem is a little too advanced for someone completly new to programming and C language in particular.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,951 posts
since Aug 2005
Mar 6th, 2007
0

Re: pascal triangle?

ei,, tnx again for your replies,,,
yup im only new to this, im already working on this for 2 weeks,, this is my code:
  1. #include<stdio.h>
  2. int value,count1,count2,count3,temp;
  3. main()
  4. {
  5. clrscr();
  6. temp=1;
  7. printf("Enter number of rows:");
  8. scanf("%d", &value);
  9.  
  10.  
  11. for(count1=1; count1<=value; count1++)
  12. printf(" ");
  13. {
  14. for(count2=value; count2>=count1; count2--)
  15. printf(" ");
  16. for(count3=1; count3<=temp; count3++)
  17. printf("%d",count1,count2,count3);
  18. printf("\n");
  19. temp+=2;
  20. }
  21. getche();
  22. }

but, my output is this:
  1. 1
  2. 222
  3. 3333
  4. 44444
  5. 555555
  6. etc......
i bet i got a wrong formulation for this stuff, and my deadline is on saturday,, hoping 4 ur nice consideration... tnx alot
Last edited by WaltP; Mar 6th, 2007 at 12:26 pm. Reason: Added code tags, learn to use them. And use the PREVIEW button...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
stringgader is offline Offline
6 posts
since Mar 2007
Mar 6th, 2007
1

Re: pascal triangle?

@ stringgader. The code that goutham_see posted for you, works very well. Why don't you compare his with yours and learn what is not working with yours?.

In your last post I see that you make the declaration of variables ALL Global. I don't think that's what you want even when is going to work. What you want to do is to declare them after the left bracket in main, in this case.

The function:
Quote ...
clrscr();
is not necesary there. Is not doing anything for your, and above anything else, it makes your code not portable, which is something that you should always shoot for.

Same with
Quote ...
getche();
your could very well use the standard getchar().
Last edited by Aia; Mar 6th, 2007 at 6:48 pm. Reason: not important to know
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006

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.
Message:
Previous Thread in C Forum Timeline: Project
Next Thread in C Forum Timeline: Need help with string manipulation and seg faults





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


Follow us on Twitter


© 2011 DaniWeb® LLC