ProgIng - Programación en Ingeniería
Loading...
Searching...
No Matches
Ejemplo033.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3
4#define N 1000
5
6float validar2(float a, float min, float max, char *str)
7{
8 if(a>min&&a<max)
9 return a;
10 printf("Ingrese el valor de %s: ", str);
11 scanf("%f", &a);
12 if(a>min&&a<max)
13 return a;
14 else
15 return validar2(a, min, max, str);
16}
17
18float validar(float min, float max, char *str)
19{
20 float a;
21 printf("Ingrese el valor de %s: ", str);
22 scanf("%f", &a);
23 if(a>min&&a<max)
24 return a;
25 else
26 return validar(min, max, str);
27}
28
29float asen(float x, int n)
30{
31 int i;
32 float asx, fct;
33 for(i=0, asx=0, fct=x; i<n; i++)
34 {
35 asx+=fct;
36 fct*=((2*i+1)*x*x/(2*i+3));
37 fct*=((2*i+1.0)/(2*(i+1)));
38 }
39 return asx;
40}
41
42int main(int argc, char *argv[])
43{
44 int n=0;
45 float x=-1, asx;
46 if(argc==3)
47 x = atof(argv[2]);
48 if(argc&2)
49 n = atoi(argv[1]);
50 n = (int)validar2(n, 1, N, "n");
51 x = validar2(x, -1, 1, "x");
52 asx = asen(x, n);
53 printf("asen(%f) = %f\n", x, asx);
54 return 0;
55}
#define N
#define max
#define min
double fct(double x, int n)
Definition Ejemplo029.c:34
float validar(float min, float max, char *str)
Definition Ejemplo033.c:18
float asen(float x, int n)
Definition Ejemplo033.c:29
float validar2(float a, float min, float max, char *str)
Definition Ejemplo033.c:6
int main(void)
Definition Ejemplo_035.c:15