Homework 18: Multi-file programs
Name: _____________________________________________ Alpha: ___________________
Describe help received: ________________________________________________________
- Due before class on Wednesday, March 1
- This homework contains code to be submitted electronically.
Put your code in a folder called
hw18and submit using the204subcommand. - This is an electronic homework and you do not need to print out anything to turn in during class.
Assignment
- Required reading: Sections 4 (Recursion) and 5 (The structure of multi-file programs) from the Unit 5 notes,
-
Here is a program with a
#includestatement for a header file that you will complete:
(You can download that file from this link.)#include <stdio.h> #include "countdown.h" int main() { int n; do { printf("Enter n: "); fflush(stdout); } while (scanf(" %d", &n) != 1); // this calls the function YOU have to write! countdown(n); return 0; }You may not change that program! Instead, you need to make a header file
countdown.hand a definitions filecountdown.cthat contain (respectively) the prototype and definition for thecountdownfunction.The
countdownfunction should have the following prototype:
that prints out the numbers fromvoid countdown(int n);ndown to 1 and then prints out the message "hooray!". For example, callingcountdown(6);should result in6 5 4 3 2 1 hooray!
You are strongly encouraged to write the
countdownfunction recursively! Here is a complete example of compiling and running your program:roche@ubuntu$gcc countdown.c main.c -o mainroche@ubuntu$./mainEnter n:3321hooray!