• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

这段C代码错在哪里,为什么无法定义上下限?

//验证输入#include#include//验证输入是一个整数long get_long(void);//验证范围上下限是否有效bool bad_limits(long begin, long end,    long low, long high);//计算a-b之间的整数平方和double sum_squares(long a, long b);int main(void){ const long MIN = -10000000L; const long MAX = +10000000L; long start; long stop; double answer; printf("This program computes the sum of the squares of" "integers in a range.\nThe lower bound should not"  "be less than -1000000 and\nthe upper bound" "should not be more than +10000000.\nEnter the" "limits (enter 0 for both limits to quit):\n" "lower limit:"); start = get_long(); printf("upper limit:"); stop = get_long(); while (start != 0 || stop != 0) {  if (bad_limits(start, stop, MIN, MAX))   printf("Plase try again.\n");  else  {   answer = sum_squares(start, stop);   printf("The sum of the squares of the integers ");   printf("form %ld to %ld is %g\n",    start, stop, answer);  }  printf("Enter the limits (enter 0 for both"   "limits to quit):\n");  printf("lower limit: ");  start = get_long();  printf("upper limit: ");  stop = get_long(); } printf("Done.\n"); return 0;}long get_long(void){ long input; char ch; while (scanf("%ld"), &input != 1) {  while ((ch = getchar()) != '\n')   putchar(ch);  printf(" is not an integer.\nPlease enter an ");  printf("integer value, such as 25, -178, or 3:"); } return input;}double sum_squares(long a, long b){ double total = 0; long i; for (i = a; i  end) {  printf("%ld isn't smaller than %ld.\n",begin, end);  not_good = true; } if (begin < low || end < low) {  printf("Values must be %ld or greater.\n", low);  not_good = true; } if (begin > high || end > high) {  printf("Values must be %ld or less.\n", high);  not_good = true; } return not_good;}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!