IPC144 Lab #3

# IPC144 Lab 3 – if-else Statements (Mr. Saul's Sections)

NOTE: When you have completed this lab, and placed answers into the file called "lab3.txt", follow the instructions (at the bottom of this lab) to submit your answers to Murray Saul's e-mail account...

### STEP 1:  Enter, compile and run the following program (call it lab3a.c):

`   main( ) { /* 1 simple if statement */`
`      int x, y;`
`      printf("Enter two numbers x and y: ");`
`      scanf("%d %d", &x, &y);`
`      if (x < y)`
`         printf("Condition is true: x is less than y\n");`
`      }`
 INPUTS OUTPUT YOUR EXPLANATION 2 3 3 2 3 3

### STEP 2:  Change lab3a.c to the following and save under the name lab3b.c:

`   main( ) { /* 2 simple if statements */`
`      int x, y;`
`      printf("Enter two numbers x and y: ");`
`      scanf("%d %d", &x, &y);`
`      if (x < y)`
`         printf("Condition 1 is true: x is less than y\n");`
`      if (y < x)`
`         printf("Condition 2 is true: x is not less than y\n");`
`   }`
 INPUTS OUTPUT YOUR EXPLANATION 2 3 3 2 3 3

### STEP 3:  Change lab3b.c to the following and save under the name lab3c.c:

`   main( ) {  /* 1 if-else statement */`
`      int x, y;`
`      printf("Enter two numbers x and y: ");`
`      scanf("%d %d", &x, &y);`
`      if (x < y)`
`         printf("Condition is true: x is less than y\n");`
`      else`
`         printf("Condition is false: x is not less than y\n");`
`   }`
 INPUTS OUTPUT YOUR EXPLANATION 2 3 3 2 3 3

### STEP 4:  Change lab3c.c to the following and save under the name lab3d.c:

`   main( ) {  /* 1 if-else statement and 1 simple if statement */`
`      int x, y;`
`      printf("Enter two numbers x and y: ");`
`      scanf("%d %d", &x, &y);`
`      if (x < y)`
`         printf("Condition 1 is true: x is less than y\n");`
`      else`
`         printf("Condition 1 is false: x is not less than y\n");`
`     if (x == y)`
`               printf("Condition 2 is true: x equal to y\n");`
`   }`
` `
 INPUTS OUTPUT YOUR EXPLANATION 2 3 3 2 3 3

### STEP 5: Change lab3d.c to the following and save under the name lab3e.c:

`   main( ) { /* 1 if-else if-else (nested if) statement */`
`      int x;`
`      int y;`
`      printf("Enter two numbers x and y: ");`
`      scanf("%d %d", &x, &y);`
`      if (x < y)`
`         printf("Condition 1 is True: x is less than y\n");`
`      else if (y < x)`
`         printf("Cond'n 1 is False + Cond'n 2 is True: y is less than x\n");`
`      else`
`         printf("Cond'ns 1 and 2 are false: x is equal to y\n");`
`   }`
` `
 INPUTS OUTPUT YOUR EXPLANATION 2 3 3 2 3 3
` `
` `

Submission Requirements:

If you are in Murray Saul's class, issue the following command to send your lab #3 answers to Murray Saul:

mail -s "144lab3" -c \$USER@learn.senecac.on.ca murray.saul@senecac.on.ca < lab3.txt

The option -s "144lab3" makes subject line appear as "144lab3" so instructor can filter these e-mails in a directory to collect all lab3 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...