在不同的编程语言中输入成绩的方法有所不同。以下是几种常见编程语言中输入成绩的方法:
C语言
在C语言中,可以使用`scanf`函数来输入成绩。以下是一个简单的示例:
```c
include
int main() {
int score;
printf("请输入成绩: ");
scanf("%d", &score);
if (score >= 90) {
printf("优秀\n");
} else if (score >= 80) {
printf("良好\n");
} else if (score >= 60) {
printf("及格\n");
} else {
printf("不及格\n");
}
return 0;
}
```
C++
在C++中,可以使用`cin`来输入成绩。以下是一个简单的示例:
```cpp
include
int main() {
int score;
std::cout << "请输入成绩: ";
std::cin >> score;
if (score >= 90) {
std::cout << "优秀" << std::endl;
} else if (score >= 80) {
std::cout << "良好" << std::endl;
} else if (score >= 60) {
std::cout << "及格" << std::endl;
} else {
std::cout << "不及格" << std::endl;
}
return 0;
}
```
Java
在Java中,可以使用`Scanner`类来输入成绩。以下是一个简单的示例:
```java
import java.util.Scanner;
public class GradeLevel {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入学生成绩: ");
int score = input.nextInt();
if (score >= 90) {
System.out.println("优秀");
} else if (score >= 80) {
System.out.println("良好");
} else if (score >= 60) {
System.out.println("及格");
} else {
System.out.println("不及格");
}
}
}
```
Python
在Python中,可以使用`input`函数来输入成绩。以下是一个简单的示例:
```python
score = int(input("请输入成绩: "))
if score >= 90:
print("优秀")
elif score >= 80:
print("良好")
elif score >= 60:
print("及格")
else:
print("不及格")
```
JavaScript
在JavaScript中,可以使用`prompt`函数来输入成绩。以下是一个简单的示例:
```javascript
let score = parseInt(prompt("请输入成绩:"));
if (score >= 90) {
console.log("优秀");
} else if (score >= 80) {
console.log("良好");
} else if (score >= 60) {
console.log("及格");
} else {
console.log("不及格");
}
```
这些示例展示了如何在不同的编程语言中输入成绩并根据成绩范围输出相应的评价。你可以根据自己的需求选择合适的编程语言和方法。