输出int和double的成绩
时间: 2023-12-24 20:04:15 浏览: 19
假设有一个整数变量`scoreInt`和一个浮点数变量`scoreDouble`,可以使用以下代码输出它们的成绩:
```
int scoreInt = 90;
double scoreDouble = 87.5;
double result = scoreInt * scoreDouble;
System.out.println("成绩是:" + result);
```
输出结果为:
```
成绩是:7887.5
```
其中,乘法运算符`*`会将整数和浮点数相乘,得到一个浮点数结果。最后,使用字符串拼接将结果输出。
相关问题
C++结构体输出总成绩
可以通过定义一个结构体,来存储学生的姓名、各科成绩以及总成绩,并在结构体内定义一个输出总成绩的函数来实现。以下是一个简单的示例代码:
```
#include <iostream>
using namespace std;
struct student {
string name; // 学生姓名
double math; // 数学成绩
double english; // 英语成绩
double chinese; // 语文成绩
double total; // 总成绩
void showTotal() { // 输出总成绩
total = math + english + chinese;
cout << name << "的总成绩为:" << total << endl;
}
};
int main() {
student s;
s.name = "张三";
s.math = 90;
s.english = 85;
s.chinese = 92;
s.showTotal();
return 0;
}
```
以上代码中,我们定义了一个名为`student`的结构体,其中包含了学生的姓名、数学、英语、语文和总成绩等信息,并在结构体内定义了一个名为`showTotal()`的函数来输出总成绩。在主函数中,我们通过结构体变量`s`来存储学生的信息,并调用`showTotal()`函数来输出总成绩。运行程序后,将会输出"张三的总成绩为:267"。
c语言输出低于平均分的成绩
好的,下面是输出低于平均分的成绩的 C 语言代码:
```c
#include <stdio.h>
int main() {
int scores[10] = {72, 85, 63, 91, 68, 77, 54, 89, 75, 80};
int sum = 0, count = 0;
double average;
for (int i = 0; i < 10; i++) {
sum += scores[i];
}
average = (double)sum / 10;
printf("平均分为%.2f\n", average);
printf("低于平均分的成绩有:");
for (int i = 0; i < 10; i++) {
if (scores[i] < average) {
printf("%d ", scores[i]);
count++;
}
}
if (count == 0) {
printf("无");
}
return 0;
}
```
在这个程序中,我们定义了一个长度为10的整型数组 `scores` 来保存学生成绩。使用 `for` 循环遍历数组,计算出所有成绩的总和,并根据总和计算平均分。然后再使用 `for` 循环遍历数组,判断每个成绩是否低于平均分,如果是就输出该成绩。最后如果没有低于平均分的成绩,就输出“无”。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)
![](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)