本文介绍了这给了我一套额外的价值观......谁能告诉我为什么?哪里有问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 <#include "stdafx.h"#include <stdio.h>#include <math.h>FILE *pg;double input_status,d = 1,r,q,r1,q1,total_perimeter;int t=0 ;int main(){errno_t err;// Open for read (will fail if file "crt_fopen_s.c" does not exist)err = fopen_s(&pg, "input.txt", "r");if (err == 0){printf("The file 'input.txt' was opened\n \n ");}else{printf("The file 'input.txt' was not opened\n");} fopen_s(&pg , "input.txt" , "r"); do { input_status = fscanf_s(pg, "%lf %lf ", &r, &q); t = t + 1; printf("point %d : r %lf q %lf \n", t, r, q);t = t + 1; input_status = fscanf_s(pg, "%lf %lf ", &r1, &q1); printf("point %d : r %lf q %lf \n", t, r1, q1); d = sqrt((r*r) + (r1*r1) - (2 * r*r1) *(cos(q1 - q))); printf("distance between %d and %d %lf \n \n ",(t-1) ,t , d); } while (input_status != EOF); return 0;} 推荐答案 ... do { input_status = fscanf_s(pg, "%lf %lf ", &r, &q); if(input_status == EOF) break; //<<---- look here t = t + 1; printf("point %d : r %lf q %lf \n", t, r, q);t = t + 1; input_status = fscanf_s(pg, "%lf %lf ", &r1, &q1); printf("point %d : r %lf q %lf \n", t, r1, q1); d = sqrt((r*r) + (r1*r1) - (2 * r*r1) *(cos(q1 - q))); printf("distance between %d and %d %lf \n \n ",(t-1) ,t , d); } while (input_status != EOF);.... d = sqrt((r*r) + (r1*r1) - (2 * r*r1) *(cos((q1 - q)*dtor))); 变量dtor是在程序顶部定义为pi / 180. 这是程序 b $ b The variable dtor is a defined at the top of the program as pi/180.Here is the program#include "stdafx.h"#include <stdio.h>#include <math.h>FILE *pg;double input_status, d,r0,q0,r,q,r1,q1,total_perimeter=0;int t=0;double dtor = 3.14159265358979 / 180.0; //<<---- notice int main() { errno_t err; // Open for read (will fail if file "input.txt" does not exist) err = fopen_s(&pg, "input.txt", "r"); if (err == 0) printf("The file 'input.txt' was opened\n\n"); else { printf("The file 'input.txt' was not opened\n"); return 0; //exit the program } //fopen_s(&pg , "input.txt" , "r"); //you really do not need this line input_status = fscanf_s(pg, "%lf %lf ", &r, &q); r0 = r; q0 = q; //save the first point for later to close the polygon if(input_status==EOF) { printf("There are no data points in the file"); return 0; //exit the program } printf("point %d: r=%lf , q=%lf\n", t, r, q); do { input_status = fscanf_s(pg, "%lf %lf ", &r1, &q1); if(input_status==EOF) break; //if no more points exit the loop t++; printf("point %d: r=%lf , q=%lf\n", t, r1, q1); d = sqrt((r*r) + (r1*r1) - (2 * r*r1) *(cos((q1 - q)*dtor))); printf("distance between %d and %d = %lf \n\n",(t-1),t,d); r = r1; q = q1; //make the previous point become the current point total_perimeter += d; //accumulate the perimeter }while(1); r1 = r0; q1 = q0; //make the new point become the first point to close the polygon d = sqrt((r*r) + (r1*r1) - (2 * r*r1) *(cos((q1 - q)*dtor))); printf("distance between %d and 0 = %lf \n\n\n",t,d); total_perimeter += d; //accumulate the perimeter printf("Total Perimiter = %lf\n",total_perimeter); return 1; } 这篇关于这给了我一套额外的价值观......谁能告诉我为什么?哪里有问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 10:36