Computer Science 433
Programming Languages
Fall 2012, The College of Saint Rose
Lecture 3: C and Unix
Date: Wednesday, September 5, 2012
Agenda
- Announcements
- First programming assignments due tonight
- Programming Language of the Day: C
- A crash course in C and Unix
Lecture Assignment 3
Due at the start of class, Monday, September 10.
Please submit answers to these questions
either as a hard copy (typeset or handwritten are OK) or by email to
terescoj AT strose.edu by the start of class. Please use a clear subject line
when submitting by email (e.g., CSC 433 Lecture
Assignment 3, Joe Student). We will discuss these
questions at the start of class, so no late submissions are
accepted.
- (5 points)
You have likely seen Java applications that take command-line
parameters (the String args[] parameter to main). Write a C
program that takes an arbitrary number of command-line parameters,
each of which should represent an integer value. Print out the sum of
the values provided. Call your C program argadder.c.
Some things to know:
- A C program that wishes to make use of command-line parameters
must declare two parameters, traditionally named argc and
argv.
- The parameter argc to the main function is a count of
how many command-line strings are included in argv, which is an
array of strings. (See the main function in the gcd example.)
- argv[0] is not the first parameter, it is the program name
itself, and this array entry for the program name is included in the
value of argc.
- (10 points) Write a C program that reads in an integer (which must be
at least 2) from the keyboard, then computes and prints out its prime
factorization.
Examples