- 1
You are making a program for a bus service. A bus can transport 50 passengers at once.
Given the number of passengers waiting in the bus station as input, you need to calculate and output how many empty seats the last bus will have. Sample Input: 126 Sample Output: 24 Explanation: The first bus will transport 50 passengers, leaving 126-50=76 in the station. The next one will leave 26 in the station, thus, the last bus will take all of the 26 passengers, having 50-26=24 seats left empty.
6 odpowiedzi
+ 9
k thirupathi rao , please do not ask for a ready code here. it does not really help you to improve your coding skills and your problem solving abilities, when you don't do it by yourself.
to get help from the community, please do a try by yourself first and put your code in playground. then link it here.
thanks for your understanding!
+ 3
k thirupathi rao
50 - passengers % 50
+ 1
k thirupathi rao
This is the program. Just take input as passengers and use this code to get output.
+ 1
#include <iostream>
using namespace std;
int main() {
int x,y,z,i;
//x is the number of total passengers a bus can transport
x=50;
//y is the number of total passengers waiting in the bus station
cin >> y;
if (y<x);
{i=x-y;
}
if (y>x);
{z=y%x;
//z is the number of passengers left
i=x-z;
}
//seats left empty
cout << i;
return 0;
}
0
Please write a program