473,395 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Coding Pascal's triangle in C++.

Hiiiiii. Want to write program in 'c' using loops, which ll give an o/p:

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1

Can anybody help me out?
Sep 2 '07 #1
7 7562
JosAH
11,448 Expert 8TB
Hiiiiii. Want to write program in 'c' using loops, which ll give an o/p:
Expand|Select|Wrap|Line Numbers
  1.  
  2.                                     1
  3.                               1           1
  4.                           1         2         1
  5.                        1      3          3       1
  6.                    1      4         6         4      1
  7.                 1      5     10        10      5       1
  8.  
Can anybody help me out?
I added [ code ] ... [ /code ] tags around that triangle and see how much different
it looks now. w.r.t. you question: sure we can help; what have you done so far
yourself and what is giving you problems?

kind regards,

Jos
Sep 2 '07 #2
I added [ code ] ... [ /code ] tags around that triangle and see how much different
it looks now. w.r.t. you question: sure we can help; what have you done so far
yourself and what is giving you problems?

kind regards,

Jos
We can use binomial and reverse of of nos i guess....bt how to use it exactly in a loop?
Sep 2 '07 #3
JosAH
11,448 Expert 8TB
We can use binomial and reverse of of nos i guess....bt how to use it exactly in a loop?
You could do that; but here's a small hint: suppose you have the following line:

1 4 6 4 1

- starting at the end at the right, add the number to the left of it:

1 4 6 4 5 (5 = 4 + 1)
1 4 6 10 5 (10= 6 + 4)
1 4 10 10 5 (10 = 4 + 6)
1 5 10 10 5 (5 = 1 + 4)

- append a one (1) at the right end:

1 5 10 10 5 1

- and there you have your new line.

kind regards,

Jos
Sep 2 '07 #4
kreagan
153 100+
We can use binomial and reverse of of nos i guess....bt how to use it exactly in a loop?
A yes, Pascals Triangle.

The easiest way (for me atleast) is to use a nested for loop. One loop to go down the triangle, another to iterate across. Using a 2d matrix also helps.
Sep 2 '07 #5
A yes, Pascals Triangle.

The easiest way (for me atleast) is to use a nested for loop. One loop to go down the triangle, another to iterate across. Using a 2d matrix also helps.

Here is the code:

< spoonfeeding deleted >

Please click the 'Help' link near the top-right corner of this page. Spoonfeeding
source code is not allowed.

kind regards,

Jos
Sep 3 '07 #6
Here is the code:

< spoonfeeding deleted >

Please click the 'Help' link near the top-right corner of this page. Spoonfeeding
source code is not allowed.

kind regards,

Jos
The question was so straight that I didn't felt if I can add much concept in it. I future I will put pseudo code instead of real code.

Thx.
Sep 5 '07 #7
JosAH
11,448 Expert 8TB
The question was so straight that I didn't felt if I can add much concept in it. I future I will put pseudo code instead of real code.

Thx.
Yep, that'd be better; a lot of posters simply copy and paste complete real
code and turn it in as if it were their own achievement. Sometimes teachers
search the internet for those answers and we don't want to be pointed at
for helping people to cheat.

kind regards,

Jos
Sep 5 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

63
by: Papadopoulos Giannis | last post by:
Which do you think is best? 1. a) type* p; b) type *p; 2. a) return (var); b) return(var); c) return var;
0
by: Statsstudent2006 | last post by:
Hello! I am a newbie, and have received my first VBA assignment. I have to write a subroutine that generates the Fibonacci sequence of numbers (the first n numbers, where n is an integer number...
25
by: GUPTAJI | last post by:
hi all, can u give me the code to create a Pascal's Triangle........... and yes, it should work thankx
5
by: singhm | last post by:
Hi guys so I have a trianlge program having hard time finishing this though, I have to develop a program which is the following: Write a program that will allow the user to enter the 3 lengths...
0
by: compiler | last post by:
hai, iam new to c,i need c-code for pascal triangle,could you please provide me the code. thanks and regards.
4
by: Aaron | last post by:
Hi, I have written a pascals triangle program. However, my program gets a floating point exception somewhere between 60 and 70 and any subsequent larger value. This is no doubt due to dividing...
19
by: lost1 | last post by:
Can someone point me in the right direction on how to get the triangle type to display. Below is a triangle class that is tested by another completely separate class. The main method of the test...
6
by: jackj | last post by:
Hi, I am first time C++ student and doing the usual tasks. This one is to create a triangle based on user input of how large (how many rows) and what symbol to use. I have managed to create a...
3
by: abraxas91 | last post by:
Hi, my name is Stephan. I've been working on this program off and on over the past few days. I have yet to perfect it. I would really appreciate any help! For some reason the output begins to...
2
by: J Ivan P Silvestre | last post by:
c #: Implementing the method Int TrianglePascal (int n) which returns the triangle to the level of Pascal N. public static int TrianglePascal(int n) { int arr = new int; for(int...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.