用c语言编程:本题要求编写程序将一个百分制成绩转换为五分制成绩。转换规则: 大于等于90分为A; 小于90且大于等于80为B; 小于80且大于等于70为C; 小于70且大于等于60为D; 小于60为E。
时间: 2023-05-19 14:02:48 浏览: 81
好的,这是一个简单的程序,以下是代码:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入百分制成绩:");
scanf("%d", &score);
if (score >= 90) {
printf("对应的五分制成绩为:A\n");
} else if (score >= 80) {
printf("对应的五分制成绩为:B\n");
} else if (score >= 70) {
printf("对应的五分制成绩为:C\n");
} else if (score >= 60) {
printf("对应的五分制成绩为:D\n");
} else {
printf("对应的五分制成绩为:E\n");
}
return 0;
}
```
输入百分制成绩后,程序会根据转换规则输出对应的五分制成绩。
相关问题
C语言本题要求编写程序将一个百分制成绩转换为五分制成绩。转换规则: 大于等于90分为A; 小于90且大于等于80为B; 小于80且大于等于70为C; 小于70且大于等于60为D; 小于60为E。 输入格式: 输入在一行中给出一个整数的百分制成绩。 输出格式: 在一行中输出对应的五分制成绩。
以下是C语言的实现代码:
```c
#include <stdio.h>
int main()
{
int score;
scanf("%d", &score);
if (score >= 90) {
printf("A");
} else if (score >= 80) {
printf("B");
} else if (score >= 70) {
printf("C");
} else if (score >= 60) {
printf("D");
} else {
printf("E");
}
return 0;
}
```
输入百分制成绩后,根据转换规则通过if-else语句判断所属的五分制成绩,最后输出即可。
用c语言编写程序:本题要求实现一个函数,将非负整数n转换为二进制后输出。
以下是用C语言编写的程序,实现将非负整数n转换为二进制后输出:
```c
#include <stdio.h>
void toBinary(int n) {
int binary[32];
int i = 0;
while (n > 0) {
binary[i] = n % 2;
n = n / 2;
i++;
}
for (int j = i - 1; j >= 0; j--) {
printf("%d", binary[j]);
}
}
int main() {
int n;
printf("Enter a non-negative integer: ");
scanf("%d", &n);
printf("The binary representation of %d is: ", n);
toBinary(n);
return 0;
}
```
程序首先定义了一个名为`toBinary`的函数,该函数接受一个非负整数n作为参数,并将其转换为二进制表示形式。该函数首先定义了一个名为`binary`的整数数组,用于存储转换后的二进制数。然后使用while循环来执行转换,将n除以2并将余数存储在`binary`数组中。最后,使用for循环以相反的顺序输出`binary`数组中的元素。
在主函数中,程序提示用户输入一个非负整数,并调用`toBinary`函数将其转换为二进制表示形式。程序输出转换后的二进制数。
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)