Problema 3:Dado X real e N natural, faça um programa que calcule XN
Novamente, se N fosse fixo, por exemplo n=3, bastaria fazer
| C | Python |
|---|---|
1 int x;
2 scanf("%d", &x);
3 printf("%d", x*x*x);
|
1 x = input()
2 print(x*x*x)
|

| C | Python |
|---|---|
while (condição){
result = result*x;
cont = cont+1;
}
|
while condição:
result = result*x
cont = cont+1
|
| C | Python |
|---|---|
while (cont < n){
result = result*x;
cont = cont+1;
}
|
while cont < n:
result = result*x
cont = cont+1
|
| C | Python |
|---|---|
1 int x, n, result, cont;
2 scanf("%d %d", &x, &n);
3 cont = 0;
4 result = 1;
5 while (cont < n){
6 result = result*x;
7 cont = cont+1;
8 }
9 printf("%d", result);
|
1 x = input()
2 n = input()
3 cont = 0
4 result = 1
5 while cont < n:
6 result = result*x
7 cont = cont+1
8 print(result)
|

| C | Python |
|---|---|
1 int x, n, cont;
2 scanf("%d %d", &x, &n);
3 cont = 0;
4 while (cont < n){
5 x = x*x;
6 cont = cont+1;
7 }
8 printf("%d", x);
|
1 x = input()
2 n = input()
3 cont = 0
4 while cont < n:
5 x = x*x
6 cont = cont+1
7 print(x)
|
