上次您帮我解决了一个C++的问题,我现在想知道这条题目用C语言怎么写,麻烦了。

某公共汽车线路上共有15个站(包括起点和终点站).在每个站上车的人中,恰好在以后各站分别下去一个.要使行驶过程中每位乘客均有座位,车上至少备有多少个座位供乘客使用?
// 因为第一站上 14个 后边每个站才能下一个 同理第二站要上13个
//以此类推 下车则是 第二站下一个 第三站下2个
#include<iostream>
using std::cout;

int main()
{
int get_on,get_off;
int max,current;
max = current = 0;
for (get_on = 14,get_off = 0 ; get_off < 15 ; get_on--,get_off++)
{
current += get_on - get_off; //
if (max < current) max = current;
}
cout << "最多要准备" << max << "个座位!\n";
return 0;
}

#include <stdio.h>
int main()
{
int get_on,get_off;
int max,current;
max = current = 0;
for (get_on = 14,get_off = 0 ; get_off < 15 ; get_on--,get_off++)
{
current += get_on - get_off; //
if (max < current) max = current;
}
printf("最多要准备%d个座位!\n", max);
return 0;
}追问

后面可以注释下么?

追答

这里的C++与C语言的区别在于,打印的语句不一样。
其他逻辑不变。

温馨提示:答案为网友推荐,仅供参考
相似回答