Start by entering, saving and compiling the following program to be called lab2.c
main( ) {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("You entered %d. Now enter another number: ", num);
scanf("%d", &num);
printf("This time you entered %d\n", num);
}
INPUTS | OUTPUT
DISPLAYED
|
YOUR EXPLANATION |
3 (press Enter key) 4 |
||
3 4 | |
|
3 ab | |
|
ab 3 4 | |
|
3 4 ab | |
|
3 4ab | |
main( ) {
int num;
double num1;
printf("Enter a number: ");
scanf("%lf", &num1);
printf("You entered %3.8lf in floating point format\n", num1);
num = num1; printf("which is %d when converted to integer format\n", num);
}
Run the program using a different input each time as shown below. Record the output and try to explain why the output was produced.
INPUT | NUMBERS DISPLAYED | YOUR EXPLANATION |
1.0 | |
|
1.99999999 | ||
1.999999999 | ||
-1.99999 |
Submission Requirements:
If you are in Murray Saul's class, issue the following command
to send your lab #2 answers to Murray Saul:
mail -s "144lab2" -c $USER@learn.senecac.on.ca murray.saul@senecac.on.ca < lab2.txt
The option -s "144lab2" makes subject line appear as "144lab2" so instructor can filter these e-mails in a directory to collect all lab2 submissions.
The option -c $USER@learn.senecac.on.ca sends a copy of the e-mail message to YOUR learn account. The variable $USER is your Matrix id name assuming that you are issuing this command when logged into your Matrix account. Please keep this e-mail for the remainder of this term as proof that you sent your lab by the required deadline...