我作为初学者在练习“C”语言时编写了这个简单的代码。这里的目的是测量输入值的周长和面积。
#include <stdio.h>
#include <stdlib.h>
int main()
{
double width;
double height;
double perimeter;
double area;
printf("Enter the Width of Rectangle:");
scanf("%f", width);
printf("Enter the height of the Rectangle:");
scanf("%f", height);
perimeter = 2*(width+height);
area = width*height;
printf("Perimeter of the Rectangle=%f\n", perimeter);
printf("Area of the Rectangle=%f\n", area);
printf("Hence the problem is solved");
return 0;
}
当我编译代码时。它每次都会给我这个特定的错误。
D:\Mandeep\prog pro\Learning C\Learning_1.c||In function 'main':|
D:\Mandeep\prog pro\Learning C\Learning_1.c|12|warning: format '%f' expects argument of type 'float *', but argument 2 has type 'double *' [-Wformat=]|
D:\Mandeep\prog pro\Learning C\Learning_1.c|15|warning: format '%f' expects argument of type 'float *', but argument 2 has type 'double' [-Wformat=]|
D:\Mandeep\prog pro\Learning C\Learning_1.c|15|warning: 'height' is used uninitialized in this function [-Wuninitialized]|
后来,当我运行该程序时,在输入“矩形的宽度”后,它显示分割错误。
最佳答案
您对 scanf
的使用不正确。 scanf
期望获得一个指针:
scanf("%lf", &height);
关于c - 我面临段错误(代码已转储),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58454653/