CPSC170A
Fundamentals of Computer Science II

Lab 2

Functions

Handshakes

Details

Write a function that prints the number of handshakes it would take for every student in a classroom to shake hands with every other student. The function should have one parameter for the number of students in the classroom.

Example

The function call:

handshakes(28);

Would produce the output:

It would take 378 handshakes for all 28 students to meet each other.


Voyager 1

Write a function that prints how long it takes a signal from Voyager 1 to reach the Earth. Since Voyager 1 is constantly moving away from Earth, the function should have a parameter for Voyager’s current distance from Earth, in kilometers. The Voyager 1 communicates with radio waves, which travel at the speed of light, 299,792,458 m/s.

Example

The function call:

voyager(20884657351.0);

Would produce the output:

It takes 69663.7 seconds for a message from Voyager to reach Earth.