此问题已经在这里有了答案:
因此,我决定增加一些编程技能,通常,我是一名应用程序支持分析师,对SQL编码技能的平均水平是初学者,但是在当今的环境下,我知道我需要在自动化简单任务方面变得更好。因此,我购买了C编程课程(这不是为了获得大学学分,因此要求我不要作弊)。到目前为止,它进行得很顺利,但是我遇到了一个问题,实际上我决定改进所面临的挑战,但似乎无法解决。最初,我被要求创建一个小型应用程序,该应用程序打印出矩形的宽度,高度,周长和区域,并以硬编码方式显示宽度和高度。这很容易弄清楚。我决定增加一个额外的挑战,并让最终用户输入矩形的宽度和高度,但是它不能按照我的计划工作。编译后,我将包括我的代码以及输出。我并不是很想要一个答案,因为我想自己找到解决方案,但是如果有人可以向我指出一些文档,将不胜感激。
CODE:
#include <stdio.h>
#include <stdlib.h>
int main()
{
double width;
double height;
double perimeter;
double area;
char newLine = '\n';
printf("Please enter the width of your rectangle:");
scanf("%f", &width);
printf("Please enter the height of your rectangle:");
scanf("%f", &height);
perimeter = 2.0 * (height + width);
area = (width * height);
printf("%c",newLine);
printf("The widith of the Rectangle is: %.2f centimeters %c",width, newLine);
printf("The height of the rectangle is: %.2f centimeters %c",height, newLine);
printf("The permimeter of the rectangle is: %.2f centimeters %c",perimeter, newLine);
printf("The area of the rectangle is: %.2f centimeters %c",area, newLine);
printf("%c",newLine);
return 0;
}
输出:
[[email protected]]$ ./output/rectangle.a
Please enter the width of your rectangle:15
Please enter the height of your rectangle:12
The widith of the Rectangle is: 0.00 centimeters
The height of the rectangle is: 0.00 centimeters
The permimeter of the rectangle is: 0.00 centimeters
The area of the rectangle is: 0.00 centimeters
修复后程序的输出:
Please enter the width of your rectangle:25
Please enter the height of your rectangle:12
The height of the rectangle is: 12.00 centimeters
The widith of the Rectangle is: 25.00 centimeters
The permimeter of the rectangle is: 74.00 centimeters
The area of the rectangle is: 300.00 centimeters
您可以使用此表来了解如何在c中使用各种数据类型:https://www.geeksforgeeks.org/data-types-in-c/
修复后程序的输出:
Please enter the width of your rectangle:25
Please enter the height of your rectangle:12
The height of the rectangle is: 12.00 centimeters
The widith of the Rectangle is: 25.00 centimeters
The permimeter of the rectangle is: 74.00 centimeters
The area of the rectangle is: 300.00 centimeters
您可以使用此表来了解如何在c中使用各种数据类型:https://www.geeksforgeeks.org/data-types-in-c/