The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > General Programming > C / C++


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags:

Reply
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 09-02-2008, 08:27 AM
centro13 centro13 is offline
Novice
Join Date: Sep 2008
Posts: 3
iTrader: (0)
centro13 is on a distinguished road
Icon1 Pascal's Triangle in Turbo C

Can someone please give the correct code for Pascal's Triangle in Turbo C that looks like a real triangle..thanks..

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #2 (permalink)  
Old 09-02-2008, 08:29 AM
MrPickle's Avatar
MrPickle MrPickle is offline
PT Admin
Join Date: Nov 2007
Location: England, Lincolnshire
Posts: 332
iTrader: (0)
MrPickle is a jewel in the roughMrPickle is a jewel in the roughMrPickle is a jewel in the rough
Please post your attempt at solving the problem first.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #3 (permalink)  
Old 09-02-2008, 08:45 AM
centro13 centro13 is offline
Novice
Join Date: Sep 2008
Posts: 3
iTrader: (0)
centro13 is on a distinguished road
Code:
#include<stdio.h>
#include<conio.h>
#define p printf
void main()

{
int b,m,c;

clrscr();

p("\nHow many lines do you want?: ");
scanf("%d",&b);

p("\n\n\n\n");

for (m=0;m<b;m++)
{
p("\t\t\t");
int t=1;
for (c=m;c>=0;c--)
{
p("%4d",t);
t=t*c/(m-c+1);
}
p("\n\n");
}
getch();
}
My name is BM..

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by TeraTask : 11-18-2008 at 01:12 PM. Reason: Added code tags
Reply With Quote
  #4 (permalink)  
Old 09-02-2008, 03:31 PM
MrPickle's Avatar
MrPickle MrPickle is offline
PT Admin
Join Date: Nov 2007
Location: England, Lincolnshire
Posts: 332
iTrader: (0)
MrPickle is a jewel in the roughMrPickle is a jewel in the roughMrPickle is a jewel in the rough
Hello BM, what exactly is wrong with your code?
I tried it an it seems to work fine..

(Please use tags when posting code, thanks.)

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #5 (permalink)  
Old 09-02-2008, 09:11 PM
centro13 centro13 is offline
Novice
Join Date: Sep 2008
Posts: 3
iTrader: (0)
centro13 is on a distinguished road
Yes it works fine but it looks like a half triangle like this..


1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1


i want the pascal triangle to look like a whole triangle..thanks..

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by centro13 : 09-02-2008 at 09:14 PM.
Reply With Quote
  #6 (permalink)  
Old 09-03-2008, 09:18 AM
MrPickle's Avatar
MrPickle MrPickle is offline
PT Admin
Join Date: Nov 2007
Location: England, Lincolnshire
Posts: 332
iTrader: (0)
MrPickle is a jewel in the roughMrPickle is a jewel in the roughMrPickle is a jewel in the rough
Okay, I see what you mean now.

What you need to do is indent the each row by the amount of rows left to print.

Here's how I would do it, I've added 1 more variable and a for loop.
Code:
#include<stdio.h>
#include<conio.h>
#define p printf
int main() {
    int b, m, c, IndentCount;

    p("How many lines do you want?: ");
    scanf("%d",&b);
    IndentCount = b;

    p("\n");

    for(m = 0; m < b; m++) {
        int t = 1;
        for(int i = 0; i < IndentCount; i++)
                p(" ");
        for (c = m; c >= 0; c--) {
            p("%d ", t);
            t = t*c / (m-c+1);
        }
        p("\n");
        IndentCount--;
    }
    getch();
    return 0;
}
This tends to go dodgy when a line has a number with 2 digits in it.

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 07:54 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50