c programing

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

The equality operator used in a condition to compare 2 values to see if they are not equal is __________.

!=

Type the relational/equality operator to complete the expression: numDogs and numCats differ. numDogs _____ numCats

!=

Consider the following two sets of code: (i) (ii) if (a == 1 && b == 1) if (a == 1) { { printf("Hello"); if (b == 1)} { printf("Hello"); } }

(i) is preferred over (ii) because (i) is easier to read

Which code snipet will print the numbers from 1 to 10?

/* print the numbers from 1 to 10 */int num = 0; while (num < 10){ num += 1; printf("%d\n", num);}

Based on the following code: const int SIZE = 20; int values[SIZE]; What is the subscript of the first element in the array?

0

How many times will the following loop execute? int num = 1; while (num > 10) { printf("%d\n", num);num++; }

0

numApples is initially 7. What is numApples after: numApples += 4;

11

What does the following code display? int num1 = 1;int num2 = 0; while (num1 < 5){ num2 = num2 + 3; num1++;}printf("%d is less than %d", num2, num1);

12 is less than 5

What does the following code display? int num = 1; do{ printf("%d", num); num++;} while (num < 4);

123

If result is a double variable, what value will be stored in result after the following statement executes? result = 5 / 2;

2

After the following code runs, _____ is the final value of numItems. int numItems = 10; if (numItems < 15){ numItems = 20;}else{ numItems = 5;}

20

Based on the following code: const int SIZE = 20; int values[SIZE]; How many elements does the array have?

20

2^8 = _____

256

Which of these variable names is not legal?

3rdQuarterSales

The output from the following code is _____. int x = 2;int y = 5; if (x != 3){ printf("%d", y);}else{ printf("%d", x);}

5

What does the following code display (enter 'Nothing' if the loop never runs)? int num = 5; do{ printf("%d", num); num++;} while (num < 4);

5

Given a function definition: void CalcVal(int a, int b, int c) what value is assigned to the parameter b during this function call: CalcVal(44, 55, 66);

55

The output from the following code is _____. int x = 3;int y = 5; x = x + 1;y -= 1;x += y; printf("%d", x);

8

What is the largest possible value returned by rand() % 100?

99

Constant names should be written in _____.

ALL_CAPS

The below truth table is for the _____ logical operator. C1 C2 | Result--- --- ---------F F | FF T | FT F | FT T | T

AND

A 2-dimensional array can hold values that are different data types.

False

The output from the following code is _____. int num1 = 3;int num2 = 5; if (num1 + num2 <= 5){ printf("Less");}else{ printf("More");}

More

_____ describes two or more arrays that hold related data, and the related elements in each array are accessed with a common subscript.

Parallel arrays

Write a line of code to call a void function named PrintAge, passing the integer variable age (which has already been defined) as an argument. Do not use any spaces, and end the line with a semi-colon.

PrintAge(age);

A local variable's _____ starts at the variable's declaration and ends at the end of the function in which the variable is declared.

Scope

Based on the following code: const int SIZE = 7; double scores[SIZE]; What is the name of the array that is being declared?

Scores

What are the values of the variables a, b, and c after this code executes? int a = 7;int b = 2;int c = 0; a = a + 2;b = a - 5 + b;c = a + b * 2;a = 1; a = [a] b = [b] c = [c]

Specified Answer for: a1Specified Answer for: b6Specified Answer for: c21

After this code executes, int a = 1; int b = 2; int c = 3; while (b <= 5) { b = b * c; c += a; a++; } What are the values of: a = [a] b = [b] c = [c]

Specified Answer for: a2Specified Answer for: b6Specified Answer for: c4

After this code executes, int x = 2; int y = 0; int z = 6; while (x <= 3) { y = x * z; z += x; x++; } What are the values of: x = [x] y = [y] z = [z]

Specified Answer for: x4Specified Answer for: y24Specified Answer for: z11

A(n) _____ statement can more clearly represent multi-branch behavior involving a variable being compared to constant values.

Switch

A function definition that takes no parameters, and the call to a function that takes no parameters, must still use the parenthesis.

The answer is 4

The output from the following code is _____. int speed = 60;printf("The speed of the car was %d MPH.", speed);

The speed of the car was 60 MPH.

The following loop was intended to calculate the sum of the integers from 50 down to 1. What is wrong with the code? num = 50; sum = 0; while (num > 0) { sum += num; }

The variable num is not decremented within the loop.

A function definition that takes no parameters, and the call to a function that takes no parameters, must still use the parenthesis.

True

A function that returns a value must contain a return statement to insure the correct value is returned.

True

It is possible to nest a loop inside another loop which is nested inside a 3rd loop.

True

Processing a large number of items in an array is usually easier than processing a large number of items stored in separate variables.

True

The counter variable in a for loop can be used as the subscript of an array.

True

The following code snippet may generate an error due to exceeding the boundaries of the array. const int SIZE = 4;int myArray[SIZE]; for (int i = 0; i <= SIZE; i++){ myArray[i] = 10;}

True

The logical OR operator short circuits to true if the first operand is true, and skips evaluating the second operand.

True

The pow() function returns a value.

True

To loop through all the elements of a two-dimensional array, _____ is used.

a pair of nested loops

Values passed to a function can be _____.

all of the above

Multiple arguments passed to a function are separated by _____.

commas

The valid statement is _____

functions defined below main() must have a function prototype

Comparing strings, "Three" is _____ "Four".

greater than

Comparing strings, "program" is _____ "Programing".

greater than

Write a line of code to create the first line of an if statement to see if the variable age is at least 21, separating each item with one space. Do not include the opening brace.

if (age >= 21)

Write a line of code to create the first line of an if statement to see if the variable numCars is at least 4 and the variable houseSize is at least 5000 (in that order), separating each item with one space. Do not include the opening brace.

if (numCars >= 4 && houseSize >= 5000)

the data type returned by 17 % 3 will be a(n) _____.

int

int CalcValue(int num1, int num2, int factor){ int answer; answer = (num1 + num2) * factor; return value;}

it should return answer

Write the expression (condition) so that the while loop will continue to loop until the user enters 'n'. Separate each item with 1 space. char keepGoing = '-'; while (_____){// loop body goes hereprintf("Continue? "); scanf(" %c", &keepGoing); }

keepGoing != 'n'

A sentinel-controlled loop _____.

loops until a certain value is received

_____ is a valid name for a function.

myFunc

_____ is the problem with the following code snippet, which determines the price someone pays to enter a movie theater based on their age. int age = 0;double price = 0.0; printf("Enter the patron's age: ");scanf("%d", &age); if (age >= 65){ price = 7.50; // Senior rate}else if (age >= 5){ price = 10.00; // Normal rate}else{ price = 2.50; // Child rate}

nothing

Which statement(s) will add 1 to the variable num?(select all that apply)

num = num + 1; num += 1; num++; ++num; Answers: num = num + 1; num += 1; num =+ 1; num++; ++num;

_____ is a statement that displays the value of the integer variable myVar.

printf("%d", myVar);

When declaring a two-dimensional array, we typically think of the first subscript as the _____ and the second subscript as the _____.

rows, columns

The purpose of a flag in a program is to _____.

signal if some event occured

Write a line of code to assign the sum of the variables num1 and num2 to the variable sum, using 1 space to separate items, and ending the line of code with a semi-colon. All the variables have already been defined.

sum = num1 + num2;

The following block of code is intended to sum and display the contents of an array of doubles named myNums. The constant SIZE has been declared and initialized to a value of 10, and the array has been populated with values. The line of code that is missing is _____. double sum = 0.0; for (int i = 0; i < SIZE; i++){ _____}printf("The sum is %lf\n", sum);

sum = sum + myNums[i];

The following if - else if block of code, converted to a equivalent switch block, is: if (choice == 1){ printf("You chose 1.\n");}else if (choice == 2){ printf("You chose 2.\n");}else if (choice == 3){ printf("You chose 3.\n");}else{ printf("Make another choice.\n");}

switch (choice){ case 1: printf("You chose 1.\n"); break; case 2: printf("You chose 2.\n"); break; case 3: printf("You chose 3.\n"); break; default: printf("Make another choice.\n");}

What would the following code display? for (int counter = 0; counter <= 500; counter += 100){ printf("%d\n", counter);}

0 100 200 300 400 500

// Function Prototypedouble FindQuotient(int num1, int num2); int main(void){ int num1 = 3; int num2 = 5; double num3 = 0.0; num3 = FindQuotient(num1, num2); printf("%.1lf", num3); return 0;} // Function definitiondouble FindQuotient(int num1, int num2){ return num1 / num2;}

0.0

The difference threshold, often called the epsilon, which is used to indicate that floating-point numbers are 'close enough', is typically the value _____.

0.0001

// Function Prototype int Doubler(int x); int main(void) { int x = 5; x = Doubler(x); printf("%d", x); return 0; } // Function definition int Doubler(int x) { x = x * 2; return x; }

10

// Function Prototypeint MyFunc(int num); int main(void){ int num = 5; printf("%d", MyFunc(num)); return 0;} // Function definitionint MyFunc(int myValue){ if( myValue < 3) { return 3; } else { return 10; } return 20;}

10

The number of values that could be stored in 7 bits is _____.

128

3 + 5 * 2 = _____

13

What does the following code display? int x = 0; do{ x++; printf("%d", x); x += 1;} while (x < 6);

135

What does the following code display? const int MAX = 6;int counter = 0;int total = 0; for (counter = 1; counter < MAX; counter++){ total += counter;}printf("%d", total);

15

// Function Prototypeint SquareAndAdd(int x); int main(void){ int num1 = 3, num2 = 9, num3 = 27; num1 = SquareAndAdd(num1); num3 = num1 + num2 + num3; printf("%d", num1); return 0;} // Function definitionint SquareAndAdd(int x){ x = x * x; x = x + x; return x;}

18

Based on the following code: const int SIZE = 20; int values[SIZE]; What is the subscript of the last element in the array?

19

Based on the following code: int myArray[5][5];int num = 0; for (int i = 0; i < 5; i++){ for (int j = 0; j < 5; j++) { myArray[i][j] = num; num++; }} the value in myArray[4][0] is _____.

20

Given: int yearsArray[4]; yearsArray[0] = 1999;yearsArray[1] = 2014;yearsArray[2] = 2017; What value is stored in yearsArray[1]?

2014

How many times will the variable num be displayed? int num = 0; for (int i = 1; i < 5; i++){ for (int j = 1; j < 8; j++) { printf("%d\n", num); }}

28

// Function Prototype int Doubler(int x); int main(void) { int x = 3; Doubler(x); printf("%d", x); return 0; } // Function definition int Doubler(int x) { x = x * 2; return x; }

3

Based on the following code: const int SIZE = 5;int numbers[SIZE] = { 1, 2, 3, 4, 5 }; What value is stored in numbers[2]?

3

How many times will this following loop execute? int x = 2; while (x < 5) { printf("%d\n", x); x = x + 1; }

3

The output from the following code is: int a = 5, b = 3, c = 7, x; if (a > c){ x = 1;}else if (b > c){ x = 2;}else{ x = 3;}printf("%d", x);

3

What will the following code display? for (int x = 3; x < 7; x++){ for (int y = 1; y < 3; y++) { printf("%d", x); } printf("\n");}

33 44 55 66

After the following code executes, what will be the value stored in the variable num? int num = 5; num--;

4

numCars is initially 55. What is numCars after: numCars = numCars + 3;

58

After the following code runs, _____ is the final value of numItems. int numItems = 0; int bonusVal = 5;if (bonusVal > 10) bonusVal = bonusVal - 1; numItems = bonusVal; numItems = numItems + 1;

6

What does the following code display? int i = 0;int total = 0; for (i = 0; i < 6; i++){ total = total + i;}printf("%d", i);

6

To represent 6.02x1023, use _____.

6.02e23

Based on the following code: double myArray[8][8]; How many elements does the array have?

64

char names[][10] = {"Tom", "Bill", "Sue", "Mark"};double scores[] = {87.0, 96.1, 75.5, 83.9}; What score would names[2] have?

75.5

Type the relational/equality operator to complete the expression: numDogs and numCats are the same . numDogs _____ numCats

==

__________ is printed by the following code. for (i = 0; i < 3; i++) { for (j = 1; j < 5; j++) { printf("?"); } printf("\n"); }

???? ????

The pieces of data that are passed to a function are called _____.

Arguments

A function's block of statements may include _____.

Branches (decisions), loops(repetition), calls to other functions

To cause a loop to immediately exit, use the _____ statement.

Break

The difference between chars and strings is _____.

Characters literals are enclosed in apostrophes (single quotes) and strings literals are enclosed in quotation marks (double quotes). char variables can hold only a single character but string variables can hold multiple characters. char is a C built-in data type and string is not

Based on the following code: const int SIZE = 7;double scores[SIZE]; What is the data type of the array elements?

Double

_____ is the problem with the below code snippet, which assigns either a grade of 'P' ("Passing") or 'F' ("Failing"). char grade = 'P';int score = 0; printf("Enter the score: ");scanf("%d", &score); if (score < 60); grade = 'F'; printf("Your grade is %c.\n", grade);

Everyone fails since the if statement ends with a semi-colon

A good programming process is to write the entire program, then incrementally remove bugs one at a time.

False

A statement in one function can access a local variable in another function.

False

A while loop ends with a semi-colon.

False

Although it is possible to create a 3-dimensional array, it is not possible to create an array of more than 3 dimensions, since our world only has 3 dimensions.

False

Assume the variables a = 2 and b = 4, how does the following expression (condition) evaluate? a == 4 || b > 2

False

Calling a function and defining a function mean the same thing.

False

Concerning a 2-dimensional array (or a table), the values in a column go left and right.

False

Functions are not allowed to accept multiple arguments.

False

Given a = 2, b = 4, and c = 6, how does the following expression (condition) evaluate? (b + 1 > 4) && ((a > 2) && !(c == 5))

False

Given the code: int x = 2;int y = 3;int temp; x = y;temp = x;y = temp; will cause the values in the variables to be swapped so that after the code executes x = 3 and y = 2.

False

Given: char myName[20] = "George"; myName can later be re-assigned using code such as: myName = "Mary";

False

Given: int yearsArray[4]; This is a valid statement: yearsArray[4] = 2004;

False

It is not necessary to initialize accumulator variables.

False

It is not possible to increment the counter variable in a for loop by any value other than 1.

False

The below is a valid code snippet. int age = 0; printf("Enter your age: ");scanf("%d", &age); if (30 <= age <= 39){ printf("You are thirty-something.\n");}

False

The counter variable in a loop should not be used for anything except counting the iterations of the loop.

False

The else part of an if block is required

False

The following code will compare two arrays to see if they are equal: int Array1[5] = { 2, 4, 6, 8, 10 };int Array2[5] = { 2, 4, 6, 8 ,10 }; if (Array1 == Array2){ printf("The arrays are equal");}

False

The following expression will validate that degreesF is between 68 and 74, inclusive. ((degreesF >= 68) || (degreesF <= 74))

False

The oval is the correct flowchart symbol to use to represent an if block.

False

When a function executes a return statement, and there is additional code below the return statement, the additional code is also executed.

False

You cannot display the contents of the counter variable in the body of a for loop.

False

char myName[6] = "George"; is a valid statment.

False

const int anArray[5]; is a valid line of code.

False

A _____ loop is meant to repeat a specific number of times.

For

The output from the below code is _____. int num1 = 1;int num2 = 2;printf("Number 1: %d Number 2: %d", num2, num1);

Number 1: 2 Number 2: 1

A statement, usually appearing at the top of the program, which declares the existence of a function, but does not define the function, is a function _____.

Prototype

What are the values of the variables x, y, and z after this code executes? int x = 3;int y = 5;int z; x = y + 2;y = 4;z = x + y * 2;printf("%d", z - 1); x = [x] y = [y] z = [z]

Specified Answer for: x7Specified Answer for: y4Specified Answer for: z15

// Function Prototypesvoid Line1();void Line2();void Line3(); int main(void) { printf("The 3 programming constructs are: "); Line1(); Line2(); Line3(); return 0;} // Function definitionsvoid Line1(){ printf("Sequence, ");} void Line2(){ printf("Decision, ");} void Line3(){ printf("and Repetition");}

The 3 programming constructs are: Sequence, Decision, and Repetition

The output from the following code is _____ (#include <string.h> and #include <math.h> have been added). const double PI = 3.141;char message[] = "The area is ";double radius = 1.0;printf("%s %.3lf sq. in.", message, pow(radius, 2.0) * PI);

The area is 3.141 sq. in.

_____ is the problem with the following code snippet. int numCars = 2;int drivers = 0; if (numCars = 3) drivers = 3;

The expression (condition) is always true

_____ is the reason the following code snippet could possibly generate an error. const int SIZE = 4;int myArray[SIZE]; for (int i = 0; i <= SIZE; i++){ myArray[i] = i;}

The last iteration of the loop exceeded the upper bounds of the array

A function's parameter definitions act like local variable definitions.

True

Although you can compare numeric values in C, you cannot compare strings directly - you would need to use the strcmp() function.

True

An array's size cannot be changed while the program is running.

True

An if block can be nested inside another if block.

True

Given the code: int myArray[5] = { 1, 2, 3, 4, 5 }; int temp = 0; temp = myArray[1];myArray[1] = myArray[2];myArray[2] = temp; will cause the values in myArray[1] & myArray[2] to be swapped so that after the code executes myArray[1] = 3 and myArray[2] = 2.

True

In a switch block, the default statement is optional.

True

It is permissible to have local variables with the same name declared in separate functions.

True

To make programs easier to maintain, many programmers use a constant to specify the size of an array.

True

You do not have to include an initialization list when you leave out the size declarator in an array definition.

True

You should not write code that modifies the contents of the counter variable in the body of a for loop.

True

in a nested loop, the inner loop goes through all of its iterations for every single iteration of the outer loop.

True

main() itself is a function.

True

scanf() will not allow a full string containing whitespace to be stored in a variable.

True

_____ is returned by a bool function.

True or False

_____ describes arrays that have rows and columns.

Two-dimensional arrays

When you call a(n) _____ function, it simply executes the statements it contains, and then it terminates.

Void

A C string must end with the special character _____.

\0

An accumulator is _____.

a variable that keeps a running sum

You can have up to _____ else if clauses in an if block.

as many as necessary

The same function may be called _____ from within main().

as many times as necessary

Write a line of code to declare and initialize a Boolean variable named isEven to false, using one space to separate items, and ending with a semi-colon.

bool isEven = false;

A(n) _____ expression has a value of either true or false.

boolean

For the result of an OR operation to be false, __________.

both the left side and the right side must be false

When a function ends due to it reaching the closing brace (and not due to executing a return statement), _____.

both the parameters and the local variables cease to exist

Write a line of code to declare an array of strings called studentNames that will hold up to 10 names of up to 30 characters (including the terminating character) each. Separate each item with 1 space (except around the brackets), and end the line with a semi-colon.

char studentNames[10][30];

Write a line of code to create a constant called MAX that will hold the size of an array that can store up to 25 decimal values. Separate each item with 1 space, and end the line with a semi-colon.

const int MAX = 25;

Write a line of code to define an integer variable named NUM_DAYS_IN_YEAR, initializing it to 365 and making it so that the number cannot be changed, using 1 space to separate items, and ending the line of code with a semi-colon.

const int NUM_DAYS_IN_YEAR = 365;

Write a single line of code to declare and initialize an array named YEARS that holds the numeric values 2016, 2017, and 2018. Make it so that these values cannot be changed. Separate each item with 1 space (except around brackets or braces), and end the line with a semi-colon

const int YEARS[] = {2016, 2017, 2018};

A variable's _____ indicates the type of data that the variable will hold.

data type

A function's return type specifies the _____.

data type of the value that the function returns

A _____ structure will execute a set of statements only under certain circumstances.

decision

A variable that is used to store the average of several test scores should be a(n) _____.

double

Write the function header (the first line of the function definition) to define a function named CalcAnswer that accepts 2 double numbers (number1 and number2, in that order) and returns a double. Separate each item with 1 space (except around the parentheses and before any commas), and do not include the opening brace.

double CalcAnswer(double number1, double number2)

Write the function prototype for the function definition below. Separate each item with 1 space (except around the parentheses and before any commas) and don't forget the ending semi-colon. double CalcMPG(int miles, double gallons){// function code goes here}

double CalcMPG(int, double); or double CalcMPG(int miles, double gallons);

Write a line of code to just define a double variable named celsiusTemperature (do not initialize it), using 1 space to separate items, and ending the line of code with a semi-colon.

double celsiusTemperature;

__________ will create an array called myValues that will hold 11 numbers, and the numbers will include a decimal point.

double myValues[11];

Each item in an array is known as an _____.

element

C can store any number, regardless of how large or small the number is.

false

In C, uppercase and lowercase letters are considered the same.

false

It is not possible to have more than 2 branches from a decision.

false

The below is a valid code snippet. int age = 0; printf("Enter your age: ");scanf("%d", &age); if (age >= 13 && <= 19){ printf("You are a teenager.\n");}

false

The following code declares a variable named num and assigns it an initial value of 5. num = 5;

false

The following code takes the value in the variable total and assigns it to the variable num. total = num;

false

Given the statement printf("%d ", i); that will be the only statement in the body of a for loop, which for statement will print the sequence: 3 7 11 15 19 You can assume that the counter variable, i, has already been declared as an integer.

for (i = 3; i <=19; i += 4)

Given the statement: int myArray[100]; __________ will initialize all the elements of myArray to a value of 100.

for (int i = 0; i < 100; i++){ myArray[i] = 100;}

Write the missing line for a for loop that will count down and display the numbers from 10 to 0 inclusive. Separate each item with 1 space (except around the parentheses). int num = 0; printf("Prepare for liftoff!\n");_____{ printf("%d\n", num);}printf("Liftoff!\n");

for (num = 10; num >= 0; num = num - 1)

Write the missing line for a for loop that will display the odd numbers from 1 to 100 inclusive. Separate each item with 1 space (except after opening parentheses, before closing parentheses, and before semi-colons). int oddNum = 0; printf("The odd numbers, from 1 to 100.\n");_____{ printf("%d\n", oddNum);}

for (oddNum = 1; oddNum <= 100; oddNum = oddNum + 2)

The modern Summer Olympic Games stared in 1896, and normally occur every 4 years. Write the missing line of a for loop that will display the years that the Summer Olympic Games should have occurred, up to and including 2016. Use the variable year as the loop counter, and separate each item with 1 space (except around the parentheses). int year; printf("These are the years that the modern Summer Olympic Games should have occurred\n");_____{printf("%d\n", year);}

for (year = 1896; year <= 2016; year = year + 4)

When the number of repetitions needed for a set of instructions is known before they are executed in a program, the best repetition structure to use is a(n) _____.

for loop

Translate the below description to an if - else statement as directly as possible, putting all the code on one line. Use { }, end statements with semi-colons, separate items with 1 space, and place spaces around the braces. If numItems is less than 10, assign 0 to discount - otherwise, assign 10 to discount.

if (numItems < 10) { discount = 0; } else { discount = 10; }

Which block of code will assign 0.2 to the commission variable if the sales variable is greater than or equal to 10000?

if (sales >= 10000){ commission = 0.2;}

The below block of code, re-written with correct indentation, is: if (score < 60){ printf("F");}else{if (score < 70){ printf("D");}else{if (score < 80){ printf("C");}else{if (score < 90){ printf("B");}else{ printf("A");} } } }

if (score < 60){ printf("F");}else{ if (score < 70) { printf("D"); } else { if (score < 80) { printf("C"); } else { if (score < 90) { printf("B"); } else { printf("A"); } } }}

Which statement validates that the variable speed is between 0 and 100 inclusive?

if (speed >= 0 && speed <= 100)

How many times will the following loop execute? int num = 1; while (num = 10) { printf("%d\n", num);num++; }

infinite

The variable numSpoons, which keeps track of the number of spoons in a kitchen, should use _____ as the data type.

int

Write the function header (the first line of the function definition) to define a function named AddNums that accepts 2 integer numbers (num1 and num2, in that order) and returns an integer. Separate each item with 1 space (except around the parentheses and before any commas), and do not include the opening brace.

int AddNums(int num1, int num2) Correct Answer:

The function prototype that would return an integer is __________.

int MyFunc(void);

Write the function header (the first line of the function definition) to define a function named RandNum that accepts no arguments and returns an integer. Separate each item with 1 space (except around the parentheses), and do not include the opening brace.

int RandNum()

__________ will define degrees to be an array that will hold numbers without decimal points, with elements ranging from degrees[0] through degrees[30]

int degrees[31];

_____ will declare and initialize an array that holds the first five sequential even numbers.

int myNums[] = { 2, 4, 6, 8, 10 };

Write a line of code to define an integer variable named numStudents, initializing the variable to 21 in the definition, using 1 space to separate items, and ending the line of code with a semi-colon.

int numStudents = 21;

Write a single line of code to declare and initialize an array named oddNums that holds the values 1, 3, 5, 7, and 9. Separate each item with 1 space (except around brackets or braces), and end the line with a semi-colon.

int oddNums[] = {1, 3, 5, 7, 9};

The problem with the following code, which is intended to display the first 5 odd numbers, is _____. int num = 1; while (num != 10){ printf("%d\n", num); num = num + 2;}

it is an infinite loop

An invalid reason for using functions in your code is _____.

it makes the code execute faster

Write a line of code to just assign the character 'A' to a variable named letterGrade that has already been defined and can only hold a single character, using 1 space to separate items, and ending the line of code with a semi-colon.

letterGrade = 'A';

In general terms, a program that is broken into smaller units of code, such as functions, is known as a(n) _____ program.

modularized

_____ assigns the value of 5 to myArray element 0 (myArray[] has already been defined as an array of integers).

myArray[0] = 5;

Write a line of code to assign the value 5 to the 5th element of an array named myArray. Separate each item with 1 space (except around the brackets), and end the line with a semi-colon.

myArray[4] = 5;

Given the following array declaration: int myArray[50]; _____ will exceed the boundaries of the array.

myArray[55] = 7;

_____ is an example of lower camel case.

myVariable

The arguments in the line of code that invokes a function must match the parameters in the function header in all of the following ways except __________.

name of arguments

An infinite loop is a loop that _____.

never ends

Write the expression (condition) so that the while loop will continue to loop until the user enters a valid number. Separate each item with 1 space (except around any parentheses you might use). int num; printf("Enter a number between 1 and 100 inclusive: "); scanf("%d", &num); while (_____){printf("The number entered is not between 1 and 100 inclusive.\n"); printf("Please re-enter the number: "); scanf("%d", &num); }

num <= 0 || num >= 101

Write a line of code to invoke a function named RandNum, which accepts no parameters, and storing the return value in a variable called num (which has already been defined). Separate each item with 1 space (except around the parentheses), and end the line with a semi-colon.

num = RandNum();

The output from the following code is: int num = 2; switch (num) { case 1: printf("num is 1"); case 2: printf("num is 2"); case 3: printf("num is 3"); default: printf("default"); break; }

num is 2num is 3default

The output from the following program is _____. int num = 5; switch (num){case 1: printf("num is 1"); break; case 3: printf("num is 3"); break; case 5: printf("num is 5");break; case 7: printf("num is 7");}

num is 5

Write a line of code to get the number of characters in the string variable named firstName, and store the number in a variable named numChars, separating each item with one space, and ending the line with a semi-colon.

numChars = strlen(firstName);

Write the expression (condition) so that the while loop will iterate until the integer variable numEntered is negative. Separate each item with 1 space. while (_____) {

numEntered >= 0

Convert the following if - else block into a conditional expression (the shorthand notation of a decision), separating each item with one space, and ending the line with a semi-colon. if (numDoors > 2){ numPeople = 4;}else{ numPeople = 2;}

numPeople = (numDoors > 2) ? 4 : 2;

Write a line of code to assign the value of 100 to an integer variable named numPoints that has already been defined, using 1 space to separate items, and ending the line of code with a semi-colon.

numPoints = 100;

The output from the below code is _____. printf("one" "two" "three");

onetwothree

The pieces of data that are received by a function go into _____.

parameters

When an argument is _____, only a copy of the argument's value is passed into the parameter variable.

passed by value

A _____ loop always executes at least 1 time

post-test

ppl = ppl * period; is equivalent to _____.

ppl *= period;

A while loop is a _____ type of loop.

pre-test

The following block of code is intended to display the contents of an integer array named myNums. The constant SIZE has been declared and initialized to a value of 10, and the array has been populated with integer values. The line of code that is missing is _____. for (int i = 0; i < SIZE; i++){ _____}

printf("%d\n", myNums[i]);

Write a line of code to display the value of the integer variable named numPCs followed by a new line, using 1 space after any commas and ending the line of code with a semi-colon.

printf("%d\n", numPCs);

To display two numeric variables (num1 and num2) on screen separated by a tab, use _____.

printf("%d\t%d", num1, num2);

Write a single line of code to display on screen the text "Hello World", ending the line of code with a semi-colon, and also make the next output start on a new line.

printf("Hello World\n");

Write a single line of code to display the text "Hello" and "World", putting each word on a separate line of output and also making the next output start on a new line, and ending the line of code with a semi-colon.

printf("Hello\nWorld\n");

If there is no else clause for an if block, and the condition is not true, _____.

program flow continues with the statement following the if block

>, <, and >= are all _____ operators.

relational

The last statement in a C program is _____.

return 0;

Write a line of code to read input from the keyboard and store it in a char array variable (a string) named firstName, using 1 space after any commas, and ending the line of code with a semi-colon.

scanf("%s", firstName);

Write a line of code to get the 2nd element from an array named studentScores and assign it to the variable score. Separate each item with 1 space (except around the brackets), and end the line with a semi-colon.

score = studentScores[1];

To compare 2 strings to see if they are equal, use _____.

strcmp()

Write a line of code to create the first line of a switch statement that is based on the variable menuChoice, separating each item with one space. Do not include the opening brace.

switch (menuChoice)

A do-while loop _____.

tests its expression (condition) at the bottom of the loop

The scope of a global variable is _____.

the entire program

The problem with the below function definition is _____. void MyFunc(int num + 5)

the function's parameter cannot be an expression

The problem with the below code, which should print the numbers 0 through 4, is _____. int num = 0; while (num < 5);{ printf("%d", num); num++;}

the while loop ends with a semi-colon

To convert a character to uppercase, use ____.

toupper()

A double variable can hold integer values.

true

A variable can hold only 1 value at a time.

true

A variable that is used to store the average of several test scores should be a(n) _____.

true

Although indentation is not required, it makes your code much easier to read.

true

An int variable can hold negative numbers.

true

Floating-point numbers (such as a number declared as a double) should not be compared directly using the equality operator "==".

true

When you declare a constant, an initialization value is required

true

while loops execute as long as their expression (condition) is _____.

true

You can _____ to explicitly convert a value from one numeric data type to another, even if the conversion might result in a loss of data.

type cast

Write a line of code to invoke a function named CalcValue, passing it the integer variable num (which has already been defined) as an argument and storing the return value in a variable called value (which has already been defined). Separate each item with 1 space (except around the parentheses), and end the line with a semi-colon.

value = CalcValue(num);

Write the function header (the first line of the function definition) to define a function named DisplayStats that accepts a string (a character array named fName), an integer (num1), and a double (examScore), in that order, and returns nothing. Separate each item with 1 space (except around the parentheses and before any commas), and do not include the opening brace.

void DisplayStats(char fName[], int num1, double examScore)

The function's return statement causes execution to jump back to _____

where the function was called

Write the missing line for a while loop that will display "CPT 234" 10 times. Separate each item with 1 space (except around the parentheses). int num = 1; _____{ printf("CPT 234\n"); num = num + 1;}

while (num <= 10)

Write the missing line for a do-while loop that will display "Test #" followed by the sequential number from 1 to 5. Separate each item with 1 space (except around the parentheses), and end the line appropriately. int num = 1; do{ printf("Test #%d\n", num); num = num + 1;} _____

while (num <= 5);

An infinite loop is a loop _____.

whose expression (condition) always evaluates as true

_____ is a valid assignment statement

x = 12345;

The problem with the following function is __________. int Sum(int x, int y) { int x, y, result; result = x + y; return result; }

x and y are defined twice

Write a line of code to assign the variable x to the variable y, using 1 space to separate items, and ending the line of code with a semi-colon. Both x & y have already been defined.

y = x;


Set pelajaran terkait

Parent Child FINAL (Chapters 47, 48, 49, 50, 51, 52, & 53)

View Set

Chapter 7: Measuring Domestic Output and National Income

View Set

BADM 310: Final Exam (Chapter 12 Learnsmart)

View Set

MKTG 351: Test 2 Review - Chapter 9

View Set

ECON 112 - Chapter 12 - Production and growth

View Set