14,932,748 members
See more:
Write a program that calculates the Pi number from the following equation to the sentence 10, 20, ..., 100, and prints the values obtained in the appropriate form.
pi=4(1-1/3 +1/5 -1/7 +...)

What I have tried:

Write a program that calculates the Pi number from the following equation to the sentence 10, 20, ..., 100, and prints the values obtained in the appropriate form.
Posted
Updated 31-Mar-21 23:43pm
v2
BillWoodruff 31-Mar-21 8:53am

homework: just do it.

## Solution 1

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

## Solution 2

Quote:
Write a program that calculates the Pi number from the following equation ...

This is not a question, this your homework.

You are learning and homework is training, nobody can do it for you.
Do you think Usain Bolt asked someone to train for him when he was a beginner ?

You show no attempt to solve the problem yourself, you have no question, your main effort is pasting the requirement, you just want us to do your HomeWork.
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.

Take a sheet of paper and a pencil. Use your brain and solve the problem by hand. Since Harry Potter didn't gave you the solution, there is no magic, and the solution didn't jump to your face.
You solved the problem by following a procedure, that procedure is your algorithm. You need to write down the steps in a mechanical manner (computer like). The program will follow those steps.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

## Solution 3

You have to compute the π approximation using an iterative formula.
So, start using a variable of the proper type, say
C#
`double pi = 0.0;`

then implement a loop and at each iteration add the inverse of the nth odd number (multiplied by four)
C#
`double term = 4.0/(2*n+1);`

That's all.
Yalem Anley 8-Apr-21 1:49am

Write a PHP program to accept 3 numbers from form and compute their sum.
CPallini 8-Apr-21 1:58am

OK, done.