编写程序从键盘上任意输入3个学生的成绩,并按从大到小的顺序输出。
时间: 2024-05-06 07:18:59 浏览: 15
可以使用 Python 语言来编写这个程序。以下是示例代码:
```python
# 从键盘上输入3个学生的成绩
grades = []
for i in range(3):
grade = float(input("请输入学生{}的成绩:".format(i+1)))
grades.append(grade)
# 按从大到小的顺序排序
grades.sort(reverse=True)
# 输出排序结果
print("学生成绩从高到低的顺序为:")
for grade in grades:
print(grade)
```
运行程序后,会提示你输入3个学生的成绩。你可以依次输入这些成绩,然后程序会按照从高到低的顺序输出这些成绩。
相关问题
用python编写一程序,任意输入三个数,按从大到小顺序输出
可以的,以下是Python代码:
```
a = float(input("请输入第一个数:"))
b = float(input("请输入第二个数:"))
c = float(input("请输入第三个数:"))
if a >= b and a >= c:
if b >= c:
print(a, b, c)
else:
print(a, c, b)
elif b >= a and b >= c:
if a >= c:
print(b, a, c)
else:
print(b, c, a)
else:
if a >= b:
print(c, a, b)
else:
print(c, b, a)
```
这个程序可以让用户输入三个数,然后按从大到小的顺序输出这三个数。
编写c语言程序,由键盘任意输入三个数据,按由小到大的顺序输出
```
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:\n");
scanf("%d%d%d", &a, &b, &c);
if (a > b) {
int temp = a;
a = b;
b = temp;
}
if (a > c) {
int temp = a;
a = c;
c = temp;
}
if (b > c) {
int temp = b;
b = c;
c = temp;
}
printf("三个数由小到大的顺序为:%d %d %d\n", a, b, c);
return 0;
}
```
注意事项:
- 本程序使用了条件语句if,if else或switch case语句也可以实现。
- 本程序用了较多的变量交换,也可以使用数组或指针操作来实现。
- 输入函数scanf要添加"%d"格式控制符,读取整数类型数据。