+ All Categories
Home > Documents > ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute...

ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute...

Date post: 26-Mar-2015
Category:
Upload: grace-sutton
View: 221 times
Download: 1 times
Share this document with a friend
Popular Tags:
42
ET156 – Introduction to C Programming
Transcript
Page 1: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

ET156 – Introduction to C Programming

Page 2: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Loop Review

The statements within a while loop execute until the loop repetition condition becomes false and might never execute.

Page 3: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Loop Review

Page 4: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Loop Review

A variable used to store a value being computed in increments during a loop’s execution is called an accumulator.

Page 5: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Loop Review

A for loop can either increment or decrement the loop control variable’s value by any

value.

Page 6: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Loop Review

Page 7: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Loop Review

You want to write a program that prompts the user for a value until the user enters -1.

This is an example of a sentinel-controlled loop.

Page 8: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Loop Review

Page 9: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Loop Review

What type of loop always executes at least once?

a. Sentinel-controlled loopb. For loopc. Do-while loopd. Counter-controlled loop

Page 10: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Loop Review

Page 11: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Pointers

A variable that has a memory address as its value is called a pointer.

Page 12: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Process Flow

The process of testing flow of control between a main function and its subordinate functions is called top-down testing.

Page 13: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Integers

Loss of accuracy due to round-off errors may occur when performing mathematical operators with integer values.

a. Trueb. False

Page 14: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

ASCII codes

Which of the following characters has the lowest valued ASCII character code?

a. X b. ac. A d. 6

Page 15: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

ArraysThe subscript of the first

element in an array is 0.

The Eight Elements of Array x

Page 16: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

1-16

Figure 8.2 Arrays answer and score

Page 17: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

1-17

Figure 8.3 Program to Print a Table of Differences

Page 18: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

1-18

Figure 8.3 Program to Print a Table of Differences (cont’d)

Page 19: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Functions and arrays

A function’s return type cannot be an array.

Page 20: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Function fill_array

Page 21: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Parallel Arrays

You need to store the average rainfall, high temperature, and low temperature for each day in

the year. Average rainfall must be stored as a double. Temperatures must be stored as integers. What type of data structure could you use?

a. Enumerationb. Multidimensional arrayc. Parallel arraysd. Stack

Page 22: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Function to Add Two Arrays

Page 23: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

1-23

Function Data Areas for add_arrays(x, y, x_plus_y, 5);

Page 24: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Stacks

When using a stack, all new elements are added to the top of the stack.

Only the top element can be removed from the stack.

Page 25: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Arrays and Flags

A program sets a flag within a loop to indicate when an element has been found in an array. This program is performing a linear search.

Page 26: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

All elements in a multidimensional array have the same data type.

Page 27: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

int i = 0;myArray[]= {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}while (i < 10){

printf("%d, " myArray[i]);}

Copy this code. What changes are needed to make it work.

The way that it is written, the value 2 will be output infinitely.

Page 28: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

What will be the value of y after the following code executes?

int x = 0, n = 2;do

{x *= n + 1;n++;

}while (n < 10);

a. 0 b. 1c. 10 d. 11

Page 29: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

You want to write a program that will loop until an event occurs. This is an example of ________________.

a. an accumulator-controlled loop

b. a conditional loop

c. a counter-controlled loop

d. a sentinel-controlled loop

Page 30: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

What type of loop always executes at least once?a. Sentinel-controlled loopb. For loopc. Do-while loopd. Counter-controlled loop

A variable that stores a 1 or 0 that is used to indicate whether an

event hasoccurred or not is called?

a. an accumulatorb. a flagc. an increment operatord. a sentinel value

Page 31: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

What will be the value of y after the following code executes?

int x = 0, n = 2;

do

{

x *= n + 1;

n++;

}while (n < 10);

 a. 0 b. 1 c. 10 d. 11

Page 32: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

What will be the value of x after executing the following code? int i, j, x=0;

for (i=0; i< 3; ++i){

for(j=1; j< 2; ++j){x += i * j;}

}a. 0 b. 3 c. 6 d. 9

Page 33: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Assume that age = 18. What will be the output of the following code?

switch (age) {

case 16:

case 17:

printf("Old enough to drive/n");

case 18:

case 19:

case 20:

printf("Old enough to vote/n");

case 21:

printf("Old enough to drink/n");

}

 

a. Nothingb. Old enough to votec. Old enough to vote Old enough to drinkd. Old enough to drive Old enough to vote Old enough to drink

Page 34: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Assume that price = $4.00. What would be the value of total after executing the following code?

if (price > 100)

shipping = 20;

else if (price < 50)

shipping = 10;

else if (price < 5)

shipping = 0;

 if (price > 10)

tax = price * 0.5;

else

tax = price * 0.1;

total = price + tax + shipping;

a. 14.20b. 14.04c. 4.20d. 4.04

Page 35: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

a. 0 1 8 27 64 b. 0 1 8 27 64 125c. 0.0 0.0 0.0 0.0 0.0 d. No output

What will the output be when the following code executes?

#define SIZE 5

int main(void)

{ int cubes, i;

for (i=0; i<SIZE; ++i)

{

cubes = i * i * i;

printf(“%f “, cubes);

}

}

Page 36: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

a. 1, 2, 3, 4, 5, 6, 7, 8, 9b. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10c. No values will be output.d. The value 0 will be output infinitely.

What will be the output when the code below executes?int i = 0;while (i < 10){ printf(" The value of i is: %d”, i);} 

Page 37: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

You want to write a program that prompts the user for a value until the user enters -1. This is an example of ________________.

a. an accumulator-controlled loopb. a conditional loopc. a counter-controlled loopd. a sentinel-controlled loop

Page 38: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

A for loop _________________________________.a. will never result in an infinite loopb. increases the loop control variable’s value by 1 with every executionc. can increment the loop control variable’s value by any positive incrementd. can either increment or decrement the loop control variable’s value byany value

Page 39: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

A variable used to store a value being computed in increments during a loop’s execution is called _____________________.

a. an accumulator

b. a flag

c. an increment operator

d. a sentinel value

Page 40: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

The statements within a while loop execute _________________________.

a. at least once and continue executing until the loop repetition conditionbecomes trueb. at least once and continue executing until the loop repetition conditionbecomes falsec. until the loop repetition condition becomes false and might neverexecuted. until the loop repetition condition becomes true and might neverexecute

Page 41: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

The controlling expression for a switch statement can be of type

___________.

a. int, char, or double

b. int or double

c. int or char

d. char or double

Page 42: ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.

Using nested if statements is more efficient than using a sequence of if statements.

a. True

b. False


Recommended