To become familiar with syntax error messages generated by the gcc
compiler
The Task
Using a text editor (pico, emacs, or vi), type in the C program shown
on the back of this sheet. Type it in EXACTLY AS SHOWN, including all
spacing. (Three exceptions in the header comment: 1) insert
YOUR name as the author, 2) insert YOUR social security number, and 3)
insert YOUR e-mail address.) Make sure to save the program with the
file name proj3.c.
Compile the program using the command
gcc -ansi -Wall proj3.c
Correct any compilation errors (if any) that you receive and
recompile until you receive no errors.
Look at your directory to make sure that the file
a.out is there. This is your executable program.
Run the program a few times using different sets of
numbers to be sure that it works. To run your program,
type a.out at the prompt.
Submitting the Program
Your C source code file MUST be called proj3.c.
To submit your project, type the following at the Unix prompt.
Note that the project name starts with uppercase
'P'.
submit cs104_09 Proj3 proj3.c
To verify that your project was submitted, you can execute the following command at the Unix prompt. It will
show the file that you submitted in a format similar to the Unix 'ls' command.
submitls cs104_09 Proj3
The Program
/**************************************************************
** Filename: proj3.c
** Author: put your name here
** Date Written: 3/15/01
** SSN: put your SSN here (last 4 digits only is OK)
** Section: 0601
** E-mail: put your umbc e-mail address here
** Description: This program asks the user to enter integers,
** one at a time, until the user enters a zero.
** The largest integer is computed and displayed.
***************************************************************/
#include
int main()
{
int number; /* integer entered by the user */
int largest; /* largest entered read */
/* Prompt the user for an integer and read it */
/* Initialize the largest integer */
printf("Please input an integer, 0 to end: ");
scanf("%d", &number);
largest = number;
/* Continue to prompt and read until a zero is read */
/* Keep track of the largest integer entered */
while (number != 0)
{
if (largest < number)
{
largest = number;
}
printf("Please input an integer, 0 to end: ");
scanf("%d", &number);
}
/* Display the largest integer entered */
if(largest == 0)
{
printf("\nYou quit right away! No integer to ");
printf(" display!");
}
else
{
printf("\nThe largest integer entered was %d.\n", largest);
}
return 0;
}