necesito el factorial de w.n,w.k,w.c. Hay una forma de hacerlo sin repetir la función 3 veces
Publicado por María (1 intervención) el 17/11/2019 21:59:04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//Apenas estoy viendo estructuras y sería de gran ayuda que resolvieran mi duda(la marque en el código) n.n
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
double factorial (struct DATOS w);
double combinacion(int n,int k);
void imprimir(int n,int k);
struct DATOS
{ int n;
int k;
int c;
};
struct DATOS datos(void);
int main ()
{
int k,n;
double c1;
struct DATOS w;
w=datos();
c1=factorial(w);
//imprimir(n,k);
getch();
return 0;
}
struct DATOS datos(void)
{ struct DATOS J;
printf("introduce n:");
scanf("%i",&J.n);
printf("introduce k:");
scanf("%i",&J.k);
J.c=J.n-J.k;
return J;
}
double factorial(struct DATOS w)
//Aqui esta mi duda necesito el factorial de w.n,w.k,w.c hay una forma de hacerlo sin repetir esta funcion 3 veces.
{
double f;
int n,i;
f=1;
for(i=w.n/*w.k,w.c*/;i>1;i=i-1)
{
f=f*i;
}
printf("%.0f*",f);
return f;
}
Valora esta pregunta


0