
- Course Home
- Administration
- Assignments
- Calendar
- Online Resources
Practice Exercise #0
Write a C program that calculates the factorial of a non-negative integer and prints the result to the terminal. The integer is provided as a command line argument. Your program, when compiled, should be called "ex0" and an example of how the user should invoke it, and the resulting output, is:
bash$ ls
ex0 ex0.c
bash$ ./ex0 5
120
bash$
Tips:
- Command line arguments are available through the argv parameter of main.
- argv[0] is the first token on the command line,
i.e., the name of the executable. argc is the number
of elements in the argv array.
- For this exercise, you can assume that if there is a command line argument then it's a string representation of an integer. If you'd like to think about building building code more robust than that, man sscanf might help.
Computer Science & Engineering University of Washington Box 352350 Seattle, WA 98195-2350 (206) 543-1695 voice, (206) 543-2969 FAX