Problem on Numbers and Loops
I am having a little trouble with these two problems. Any tips would be appreciated.
[Numeric Triangle] Write a C++ program to output the following numeric triangle (n is input data, 0<n<10):
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
...
n n-1 ..3 2 1 2 3 .. n-1 n
and..
. [The Number ] The number may be calculated using the following infinite series:
= 4( )
How many terms of this series you need to use before you get the approximation p of , where:
a) p = 3.0
b) p = 3.1
c) p = 3.14
d) p = 3.141
e) p = 3.1415
f) p = 3.14159
Write a C++ program to answer this question.
thanks for any tips.. = pie
[866 byte] By [
blikstaa] at [2007-11-19 1:36:47]

# 1 Re: Problem on Numbers and Loops
This looks very much like homework ... :ehh:
Most people here don't like doing other people's homework, especially when they haven't starting anything and just ask for the answer !
# 2 Re: Problem on Numbers and Loops
sigh :mad:
Have you tried yourself? If so, ask a specific question. With what part do you have a problem? Do you even understand the problems?
This forum is not meant to let other people make YOUR homework. If you really need to let someone else do it, check out www.rentacoder.com.
# 3 Re: Problem on Numbers and Loops
nah just looking for tips.. It is a group project me and my friend are working on. We know how to make half of the triangle but it is flipped around also.
# 4 Re: Problem on Numbers and Loops
What do you mean flipped around. Just a 'quick (very quick)' thought. Run source and improve on it.
int main()
{
int Val(1);
for (int Idx(1); Idx < 8; ++Idx)
{
cout << setw(5) << Idx;
if ( Idx > 1 )
{
int Num(Idx);
Val += 2;
int Index(Idx);
for (int Kdx(1); Kdx < Val; ++Kdx)
{
if ( Index > 1 )
Num -= 1;
else
Num += 1;
--Index;
cout << setw(5) << Num ;
}
}
cout << endl;
}
return 0;
}
mop at 2007-11-9 0:40:18 >

# 5 Re: Problem on Numbers and Loops
nah just looking for tips.. It is a group project me and my friend are working on. We know how to make half of the triangle but it is flipped around also.
Then show the code and ask specifically for what you don't know how to do !
# 6 Re: Problem on Numbers and Loops
#include <iostream>
using namespace std;
void numbers(int n);
void main()
{
int n;
cout << "Please enter a number for n, greater than 0 and less than 10.";
cin >> n;
numbers(n);
}
void numbers(int n)
{
int line, spaces, stars, loop;
for (line = 1; line<=n; line++)
{
spaces = line +1;
for(loop = 1; loop <= spaces; loop++)
{
//cout << " ";
}
stars = line;
for (loop = 1; loop<=stars; loop++)
{
cout << loop;
}
cout << endl;
}
}
Output:
Please enter a number for n, greater than 0 and less than 10.8
1
12
123
1234
12345
123456
1234567
12345678
Press any key to continue
that is what we have right now.. we are confused on how to get it on the other side at the same time.
# 7 Re: Problem on Numbers and Loops
Your outpu doesn't reflect your initial post or is it me. Try the example I provided and tell me if I'm on the right track.
mop at 2007-11-9 0:43:17 >

# 8 Re: Problem on Numbers and Loops
sorry I didn't notice but when I copied the question it messed up the formatting..
here is what it is suppose to look like
(n is input data, 0<n<10):
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
...
n n-1 ..3 2 1 2 3 .. n-1 n
# 9 Re: Problem on Numbers and Loops
Right but that does not match what you're outputing.
1
12
123
1234
12345
123456
1234567
12345678
Press any key to continue
Conversly here's my output.
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6
7 6 5 4 3 2 1 2 3 4 5 6 7
Press any key to continue
mop at 2007-11-9 0:45:22 >

# 10 Re: Problem on Numbers and Loops
yes i know it doesn't match my output.. it doesn't match your output either (thank you for all your patience so far btw). we don't know how to get it to print the opposite side of the triangle to be like the problems says.
# 11 Re: Problem on Numbers and Loops
I just ran with what you gave initially (your initial post). Either way, I'll run your code and expand on it in a couple...
mop at 2007-11-9 0:47:25 >

# 12 Re: Problem on Numbers and Loops
Here ya go...
# 13 Re: Problem on Numbers and Loops
thanks guys we figured it out. didn't look at your program tho mr doom
# 14 Re: Problem on Numbers and Loops
You DIDN"T?? YOU BETTER!!!
I spent my time coding that S&$^!!!
# 15 Re: Problem on Numbers and Loops
lol I'll look at it don't worry