fence.c

来自「多学科优化软件isight培训教程初级pdf有很详细的例子讲解」· C语言 代码 · 共 39 行

C
39
字号
#include <stdio.h>
#include <math.h>

void main() {
double Length;
double Width;
double Area;
double Perimeter;

FILE *fp;

if ((fp = fopen("FenceIn.txt","r"))==NULL) {
        printf("Cannot open file. \n");
        exit(1);
    }

/*GetInputs */
fscanf(fp,"Fence Input File\n");
fscanf(fp,"The length is: %lf\n", &Length);
fscanf(fp,"The width is: %lf\n", &Width);
fclose(fp);

/*calculate values */
Area = Length * Width;
Perimeter = 2 * Length + 2 * Width;

if ((fp = fopen("FenceOut.txt","w"))==NULL) {
        printf("Cannot open file. \n");
        exit(1);
    }

fprintf(fp,"Fence Output File\n");
fprintf(fp,"The area is: %f\n",Area);
fprintf(fp,"The perimeter is: %f\n",Perimeter);

fclose(fp);
exit (0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?