Equivalente de "for" a "while"
Publicado por Lars Ewert Morales (4 intervenciones) el 07/08/2020 16:42:54
Necesito pasar de "for" a "while solo que no se donde poner la operacion "i++"
Aqui lo mismo
Agradeceria cualquier tipo de ayuda
1
2
3
4
5
6
7
8
9
10
11
12
int f (int n) {
int ans = 0;
for (int i = 1; i < n; i++) {
if (i < n/2) {
ans -= i;
}
else {
ans += i;
}
}
return ans;
}
Aqui lo mismo
1
2
3
4
5
6
7
8
9
10
11
12
13
int g (int x, int n) {
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
x *= i + 1;
continue;
}
x--;
if (x == 0) {
break;
}
}
return x;
}
Agradeceria cualquier tipo de ayuda
Valora esta pregunta


0