Introduction to C – Sample Programming Assignment #1
Objective
1.
To give students practice at typing in, compiling and running a simple program.
2.
To learn how to read in input from the user.
3. To learn how to use assignment statements and arithmetic expressions to make
calculations.
Problem:
Approaching Trains Problem
Imagine a twoway straight railway and two trains approaching each other from opposite
directions.
You need to compute how long (in minutes) would it take for these trains to
come side by side.
You will also compute how many miles each train travels till then.
Write a program to read in the distance (in miles), speeds of the trains (in miles per hour),
and output the time to meet (in miles and use 3 digits of precision after the decimal point
for displaying it) and the distance traveled by each train (use 2 digits of precision).
Input Specification
1.
The distance (in miles) between the trains will be a positive integer.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '10
 LOBO
 Natural number, Trains

Click to edit the document details