输入一个正整数n,n<=20;求n的阶层! 2、输入两个正整数m,n;求m的n次方
时间: 2023-05-27 10:07:49 浏览: 101
1. Python代码:
n = int(input())
fact = 1
for i in range(1, n+1):
fact *= i
print(fact)
2. Python代码:
m = int(input())
n = int(input())
power = m**n
print(power)
相关问题
c语言输入一个正整数n,n<=20;求n的阶层! 2、输入两个正整数m,n;求m的n次方
1. 求n的阶乘
```c
#include <stdio.h>
int main() {
int n, result = 1;
printf("请输入一个正整数n:");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
result *= i;
}
printf("%d的阶乘为:%d", n, result);
return 0;
}
```
2. 求m的n次方
```c
#include <stdio.h>
int main() {
int m, n, result = 1;
printf("请输入两个正整数m和n:");
scanf("%d %d", &m, &n);
for (int i = 1; i <= n; i++) {
result *= m;
}
printf("%d的%d次方为:%d", m, n, result);
return 0;
}
```
使用c语音输入一个正整数n,n<=20;求n的阶层! 输入两个正整数m,n;求m的n次方
1. 求n的阶乘:
```c
#include <stdio.h>
int main() {
int n, factorial = 1;
printf("请输入一个正整数n:");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
factorial *= i;
}
printf("%d的阶乘是:%d", n, factorial);
return 0;
}
```
2. 求m的n次方:
```c
#include <stdio.h>
int main() {
int m, n, result = 1;
printf("请输入两个正整数m和n:");
scanf("%d %d", &m, &n);
for (int i = 1; i <= n; i++) {
result *= m;
}
printf("%d的%d次方是:%d", m, n, result);
return 0;
}
```
阅读全文