ProgIng - Programación en Ingeniería
Loading...
Searching...
No Matches
006_valorPI.c File Reference
#include <stdio.h>
Include dependency graph for 006_valorPI.c:
Go to the source code of this file.
Functions
int
main
(int argc, char *argv[])
Function Documentation
◆
main()
int main
(
int
argc
,
char *
argv
[] )
Definition at line
3
of file
006_valorPI.c
.
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
}
src
20251
006_valorPI.c
Generated by
1.16.1