# Thread: Iterations with integers...

1. ## Iterations with integers...

I'm having trouble trying to figure out how to put this into code. The main function of this is the user inputs the number of iterations he or she thinks it will take to get close to the sixth decimal point of Pi.

π = 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11

First off I do this

#define Pi 3.1415926535

Then I know a few variables that I need which are

int Numerator, Denominator;

My question is how do you put in code that after every other fraction you want a minus and then a plus as shown up top? That's the only thing I need help with.

On a side note. I'm gonna be using a loop to ask if the user wants to do it again or try again until gets the right answer. Also, I know I'm gonna use Increments.

I appreciate any input/advice.

2. What happens to the value of sign as you go through this loop?

Code:
```int sign = 1;

for( n = 0; n < nMax; ++n )
{
sign = -sign;
}```

3. Honestly, beats me. I'm new to C and I'm taking a class on it. I early had trouble repeating the program. such as "Would you like to do this again" y/n

But I got that part down. Programming in C is soo different without the Forms.

4. Or perhaps, more obvious.

Code:
```int sign = 1;

for( n = 0; n < nMax; ++n )
{
sign = sign * -1;
}```
Do you know your "sign rules"? i.e, negative * negative = positive, negative * positive = negative...

Popular pages Recent additions