Q1) Two trains stop at regular intervals:
Train 1 stops at every 3rd station.
Train 2 stops at every 5th station.
Find:
The first common station where both trains stop.
The last common station where both trains stop.
All common stations where both trains stop.
Note: Total Number of Stations are unknown.
SOLUTION :
station = 1
last_station = station
while station <= 15:
if station % 3 == 0 and station % 5 == 0:
print(station)
print('First common station: ', station)
break
station+=1
OUTPUT :
15
First common station: 15
SOLUTION 2:
let station=15;
let last_station = station;
while (station <=15){
if(station % 3 == 0 & station % 5 ==0 ){
console.log(station);
}
last_station =station;
console.log('first common station: ',station)
station+=1;
}
**OUTPUT :**

Top comments (0)