【简答题】编写程序,输入一个长方形的两边 长,输出其面积。
时间: 2023-05-22 11:04:35 浏览: 112
非常简单,以下是示例代码:
```
#include <iostream>
using namespace std;
int main() {
int length, width;
cout << "请输入长方形的长度:";
cin >> length;
cout << "请输入长方形的宽度:";
cin >> width;
cout << "长方形的面积为:" << length * width << endl;
return 0;
}
```
希望能帮助到您!
相关问题
创建一个用glib编写的程序,简答输出123
以下是一个使用Glib编写的程序,简单输出123:
```c
#include <glib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("1\n");
printf("2\n");
printf("3\n");
return 0;
}
```
在这个程序中,我们只是简单地使用printf()函数输出了123。Glib并没有直接用到。
【简答题】编写一个程序,能够读取圆柱体的半径和长度,用下列计算公式计算圆柱面积和体积。
好的,根据您的要求,我可以为您编写一个能够读取圆柱体的半径和长度,并计算圆柱面积和体积的Java程序。以下是代码示例:
```
import java.util.Scanner;
public class Cylinder {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the radius of the cylinder: ");
double radius = input.nextDouble();
System.out.print("Enter the length of the cylinder: ");
double length = input.nextDouble();
double area = radius * radius * Math.PI;
double volume = area * length;
System.out.println("The area of the cylinder is: " + area);
System.out.println("The volume of the cylinder is: " + volume);
}
}
```
程序首先使用 Scanner 类从键盘输入圆柱体的半径和长度,然后使用圆的面积公式计算圆柱的底面积,即 area = radius * radius * Math.PI。接着,我们将圆柱的底面积乘以长度,即可计算出圆柱的体积,即 volume = area * length。最后,程序输出圆柱的面积和体积。
例如,当输入半径为 2.5,长度为 5 的圆柱体时,程序的输出为:
```
Enter the radius of the cylinder: 2.5
Enter the length of the cylinder: 5
The area of the cylinder is: 19.634954084936208
The volume of the cylinder is: 98.17477042468104
```
这就是一个简单的计算圆柱面积和体积的Java程序。