ProgIng - Programación en Ingeniería
Loading...
Searching...
No Matches
006_valorPI.c
Go to the documentation of this file.
1
#include <stdio.h>
2
3
int
main
(
int
argc,
char
*argv[])
4
{
5
float
pi;
6
int
i, n, den, sg;
7
do
{
8
printf(
"Ingrese el numero de terminos: "
);
9
scanf(
"%d"
, &n);
10
}
while
(n<0);
11
for
(i=0, pi=1; i<n; i++)
12
{
13
den = 2*i+3;
14
sg = 2*(i%2)-1;
15
pi+=(sg/(float)den);
16
}
17
pi*=4;
18
printf(
"PI = %f\n"
, pi);
19
return
0;
20
}
main
int main(void)
Definition
Ejemplo_035.c:15
src
20251
006_valorPI.c
Generated by
1.16.1