how do i combine the two

(50 pts) use for-loop to do the following tasks: calculate 6 * (1 + ¼ + 1/9 + 1/16 + … + 1/(1000*1000)). Note: the denominate is a squared number. Your answer should be very close to PI (3.1415926…).





2. (50 pts) use for-loop to print out the following 10x10 figure on screen:

0123456789

0012345678

0001234567

0000123456

0000012345

0000001234

0000000123

0000000012

0000000001

0000000000
200pts if you write it yourself :) - this isn't a homework site
If you want credit for your course, you probably ought to try to do this yourself. Your lecturer has given you enough information to start.

Both of these use a very simple loop with an integer counter variable.

In the first, you are accumulating into a double value.

In the second, you need to perform a subtraction that minimizes at zero. (That is, -1→0, -2→0, etc.)

Once you have some working code that we can help with, post back.
Good luck!
thanks you guys. I wasn't asking someone to do my work for me. I know this isn't a homework site. Doing both individually isn't the hard part for me. Its getting the two to work together. I will be happy to post my code but I know other classmates troll this site looking for someone to do their work for them instead of trying to figure out the problem. It has happened to me already. I can PM it if you want to see what I have come up with thus far. Again gents, I'm not looking for answers just guidance.
What do you mean by "combine"? You have two entirely separate tasks. What should be "together"?
yeah I know that is what I have been saying. Sometimes what he ask doesn't make any sense.
1. Two tasks. Two programs. Nothing together.

2. One program that does first one task and then the other task.

3. One program that asks the user, which of the two tasks should be done this time.

However, you have not shown the part of the task description that demands combination.
For the Second Program :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int a[10]={0,1,2,3,4,5,6,7,8,9};

for(int i=0;i<10;++i)
{
	for(int j=0;j<(10-i);++j)
	{
		if(i<=j)
		{
			for(int k=0;k<(10-i-1);++k)
				cout<<a[k];
		}
		else
		{
			cout<<"0";
		}
	}
	cout<<"\n";
}



if any error enlighten me !
Last edited on
Does he mean he just wants both things in a single program?

1
2
3
4
5
int main()
{
  do_calculate_pi_task();
  do_10_by_10_task();
}
Duoas that is exactly what he wants.
    calculate_pi.cpp                                   combined.cpp
1
2
3
4
5
6
...stuff here...

int main()
{
  ...
}
...same stuff here...

void do_calculate_pi_task()
{
  ...
}
    10_by_10.cpp
1
2
3
4
5
6
...more stuff here...

int main()
{
  ...
}
...same more stuff here...

void do_10_by_10_task()
{
  ...
}

1
2
3
4
5




int main()
{
  do_calculate_pi_task();
  do_10_by_10_task();
}

Hope this helps.
closed account (48T7M4Gy)
6 * (1 + ¼ + 1/9 + 1/16 + … + 1/(1000*1000)) approximates PI^2 not PI
kemort pm me.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <iomanip>

int main()
{
    
    double sum = 0;
    
    for( int i = 1; i < 1001; i++ )
        sum += (double)1/(i*i);
    
    std::cout << 6 * sum << std::endl;
    
    int num = 123456789;
    for( int i = 0; i < 10; i++ )
    {
        std::cout << std::setfill('0') << std::setw(10) << num << std::endl;
        num /= 10;
    }
    
    return 0;
}
Kemort I was trying to reply to you and send you my code but it won't let me because of your settings
Topic archived. No new replies allowed.