Canly 发表于 2020-7-4 19:25:05

课后作业

0. 请写一个程序,帮小甲鱼计算 20 公斤内的运费。(顺丰起步价 23 元,每超一公斤加 14 元)

#include <stdio.h>

#define FIRST_KG 23
#define NEXT_KG 14

int main()
{
      int weight, cost;

      printf("公斤 —— 花费(元):\n");
      for (weight = 1, cost = FIRST_KG; weight <= 20; weight++, cost += NEXT_KG)
      {
                printf("%3d——%3d\n", weight, cost);
      }

      return 0;
}

cost += NEXT_KG   这个玩意咋看也看不懂 有没有大佬能解释成为新手懂得...

第一个printf不写直接在最后的Printf里面写清楚也可以的吧?

qiuyouzhi 发表于 2020-7-4 19:26:49

本帖最后由 qiuyouzhi 于 2020-7-4 19:59 编辑

1,等于cost = cost + NEXT_KG
2,当然可以,随你
页: [1]
查看完整版本: 课后作业