C-Programming Chapter 2

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

Definitions can appear anywhere in the body of a function. T or F?

False a variables definition must appear before its first use in the code.

Use the statements wrote in 2.4 to write a complete program that calculates the product of three integers.

Good Luck.

Function printf always begins printing at the beginning of a new line. T or F?

False always begins printing wherever the cursor is currently located

Every statement ends with a(n) __________.

Semicolon

All variables must be given a type when they're defined. T or F?

True

The escape sequence \n when used in a printf format control string causes the cursor to position to the beginning of the next line on the screen. T or F?

True

The remainder operator can only be used with integer operands. T or F?

True

Whenever a new value is placed in a memory location, that value overrides the previous value in that location. This process is said to be __________.

destructive

Define the variables c, thisVariable, q76354, and number to be of type int.

int c, thisVariable, q76354, number;

Define the variables x, y, z and result to be of type int.

int x, y, z, result;

The escape sequence \n represents the __________ character, which causes the cursor to position to the beginning of the next line on the screen.

newline

When a value is read from a memory location, the value in that location is preserved; this process is said to be __________.

nondestructive

Prompt user to enter an integer. End your prompting message with a colon : followed by a space and leave the cursor positioned after the space.

printf( "Enter an integer: " );

Prompt the user to enter three integers.

printf( "Enter three integers: ");

Print "The product is" followed by the value of the integer variable result.

printf( "The product is %d\n", result );

Print the message "This is a C program." on one line

printf( "This is a C program.\n" );

The __________ standard library function displays information on the screen.

printf.

Compute the product of the three integers contained in variables x, y, and z and assign the result to the variable result.

result = x * y * z;

Correct the errors if ( c => 7 ) { printf( "C is greater than or equal to 7\n" ); }

=> is not an operator in C it should be changed to >=

Correct the errors scanf( "%d%d", &number1, number2 );

Add & to number2

Correct the errors printf( "The value is %d\n", &number );

Delete &

State that a program will calculate the product of three integers.

// Calculate the product of three integers

All arguments following the format control string in a printf function must be preceded by an ampersand (&). T or F?

False arguments in a printf function ordinarily should not be preceded by an &. Arguments following the format control string in a scanf function ordinarily should be preceded by an &.

Comments cause the computer to display the text after // on the screen when the program is executed. T or F?

False comments do not cause any action to be performed when the program is executed. They're used to document programs and improve their readability.

If number is not equal to 7, print "The variable number is not equal to 7."

If ( number != 7 ) { printf( "The variable number is not equal to 7.\n" ); }

Every functions body begins with _________ and ends with ________.

Left brace Right brace

All variables must be defined before they are used. T or F?

True

The _________ statement is used to make decisions.

if

Print the message "This is a C program." on two lines so that the first line ends with C.

printf( "This is a C\nprogram.\n" );

Print the message "This is a C program." with each word on a separate line.

printf( "This\nis\na\nC\nprogram.\n" );

Print the message "This is a C program." with each word separated by a tab.

printf( "This\tis\ta\tC\tprogram.\n" );

Correct the errors if ( c < 7 ); { printf( "C is less than 7\n" ); }

Remove the first semicolon after the first right parenthesis

The _________ standard library function is used to obtain data from the keyboard.

scanf.

A program that prints three lines of output must contain three printf statements. T or F?

False A printf statement with multiple \n escape sequences can print several lines.

C considers the variables number and NuMbEr to be identical. T or F?

False C is case sensitive.

The arithmetic operators *, /, %, +, and - all have the same level of precedence. T or F?

False The operators *, /, and % are on the same level of precedence, and the operators + and - are on a lower level of precedence.

Read an integer from the keyboard and store the value entered in integer variable a.

scanf( "%d", &a );

Read three integers from the keyboard and store them in the variables x, y, and z.

scanf( "%d%d%d", &x, &y, &z );

The conversion specifier ________ is used in a scanf format control string to indicate that an integer will be input and in a printf format control string to indicate that an integer will be output.

%d

Every C program begins execution at the function ________.

main


Set pelajaran terkait

Complications Occurring During Labor and Delivery

View Set

Modern Database Management - Chapter 1

View Set

when an area of a chromatid is exchanged with the matching area on a chromatid of its homologous chromosomes occurs.

View Set

Unit 3: Multiple Linear Regression

View Set

MODULE 42 - Anxiety-Related Disorders

View Set

Biology Chapter 1 "The Process of science"

View Set

CISSP - Business Continuity and Disaster Recovery

View Set

Pediatric Nursing - Cardiac Disorders

View Set

how did the naval and arms race cause the first world war?

View Set