CS1313 final (exams)

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

In C, how can you tell whether a declaration statement declares a named constant? [NOTE: You may give an example.]

"const" is in front of the statement

Re-order these lines to create a working C program that outputs the number 12. g = i * 2; } #include <stdio.h> int i; printf("%d\n", g); { i = g * h; int h = 3; int main () int g = 2;

#include <stdio.h> int main () { int h = 3; int g = 2; int I; i = g * h; g = i * 2; printf("%d\n", g); }

Write the following program. The combination of n items taken r at a time, denoted nCr and pronounced "n choose r," is the number of ways in which you can choose a subset of r items from a set of n items: nCr = (n · (n − 1) · (n − 2) · . . . · (n − r + 1)) / (1 · 2 · 3 · . . . · r) For example, if you have a standard 52-card deck of playing cards (assuming no jokers and nothing wild), then the number of possible 5-card poker hands is "52 choose 5:" 52C5 =(52 · 51 · 50 · 49 · 48) / (1 · 2 · 3 · 4 · 5) = 311,875,200 / 120 = 2,598,960 Similarly, if you have a deck of cards with no face cards (that is, no jack, no queen, no king) and only the two red suits (hearts and diamonds) but no black suits (for a total of 20 cards), then the number of possible 8-card hands is "20 choose 8:" 20C8 = (20 · 19 · 18 · 17 · 16 · 15 · 14 · 13) / (1 · 2 · 3 · 4 · 5 · 6 · 7 · 8) = 5,079,110,400 / 40,320 = 125,970 Write a program that inputs two values, which we'll name nand r, where n is the total number of items available (for example, 52 cards in a deck), and r is the size of the subgroup to be created (for example, 5 cards in a poker hand), and outputs "n choose r" (nCr). CLOSELY EXAMINE THE EXAMPLES ABOVE. Note that the numerator's high and low values won't always be 52 and 48, respectively, nor 20 and 13, respectively, and likewise the denominator's high value won't always be 5 nor 8 (but the denominator's low value will always be 1). The program's body should include the following subsections: input (with prompts), calculation, output. For this exam problem, you AREN'T required to have comments, nor idiotproofing, nor a greeting (though you should prompt the user for input), and you may use numeric literal constants in the body of your program; otherwise, all rules for programming projects (through PP #5) apply. You'll get substantial partial credit for setting up the problem correctly (for example, declarations, input, output), so if you can't write the full program, do as much as you can. DON'T GIVE UP: Every statement that you write will be worth partial credit, unless it is blatantly irrelevant to the task.

#include <stdio.h> int main() { /* main */ /* declaration section */ int n int=numerator_ int n int=denimanator int n_c_r /* greeting subsection */ printf("Hello!/n"); printf("Welcome to the program!\n"): /* input subsection */ printf("please enter the total amount of items. \n"); scans("%d", &n); printf("now please enter the size of the sub group.\n"); scans"%d", &r); /* calculation subsection */ numerator=(n*n--)*(n-r+1) denominator_=(1*1++)*r n_c_r=numerator_/denominator / *output subsection */ printf("The combination od n items taken at r time\n"); printf(" is %d", n_c_r); } /* main */

What is the output? #include <stdio.h> int main () { /* main */ printf("... by myself.\n"); } /* main */

... by myself.

How does a C compiler know that the following line is a comment? /******************************/

/* */

What is the output? #include <stdio.h> int main () { /* main */ int satsuki; satsuki = 10; printf("%d\n", satsuki); } /* main */

10

Approximate the value of 240 as a power of 10.

10^12

How many different possible values can 4 bits have?

16

What is the output? #include <stdio.h> int main () { /* main */ int a = 400; printf("1st: a = %d\n", a); a = a + 40; printf("2nd: a = %d\n", a); a = a * 2; printf("3rd: a = %d\n", a);} /* main */

1st: a=400 2nd: a=440 3rd: a=880

DESCRIBE THE CONDITION of a while loop. ("The condition is a ...")

A Boolean expression completely enclosed in parenthesis

Is an assignment an action or an equation?

Action

What is the output of the following program?If the program won't compile, then mark WON'T COMPILEand explain.If the program produces no output, then mark NO OUTPUT and explain.If the program produces garbage (undefined) output, then mark GARBAGE and explain. #include <stdio.h> int main () { /* main */ int b1 = 223, b2 = 212; printf("Big ...\n"); if (b1 < b2) { printf("Bog ...\n"); } /* if (b1 < b2) */ printf("Bug ...\n");return 0; } /* main */

Big... Bug...

What are the maximum penalties for the two penalty categories for an academic misconduct "full violation," as specified on the OU Provost's Academic Integrity webpage? Maximum grade penalty? Maximum university penalty?

F expulsion

How can you tell whether a particular declaration statement declares a named constant? NOTE: You may give an example.

Has const before

What is the output of the following program?If the program won't compile, then mark WON'T COMPILEand explain.If the program produces no output, then mark NO OUTPUT and explain.If the program produces garbage (undefined) output, then mark GARBAGE and explain. #include <stdio.h> int main () { /* main */ int a; for (a = 120; a <= 140; a += 20) { printf("Inside, a = %d\n", a); } /* for a */ printf("After, a = %d\n", a); return 0; } /* main */

Inside, a = 120 Inside, a = 140 After, a = 160

In C, how can you tell whether a statement is a declaration? [NOTE: You may give an example.]

It tells the name, location, type of data

Can a literal constant be declared?

No

What is a program?

Specific, precise, detailed collection of data and sequence of actions on that data

Suppose b1 is an int whose value is 2, and b2 is an intwhose value is 4. When the Boolean expression below is evaluated, will the evaluation short circuit? EXPLAIN. ((b1 > b2) && ((b1 - b2) == 0))

Yes, because both expressions are not true

How many values can a variable have over the course of an entire run?

as many as needed

What does the following Unix command do? cp pwd ls mkdir cd

copies files shows the working directory, writes full pathname of directory list files create directories change directory

What is the output? #include <stdio.h> int main () { /* main */ int d1, d2, d3; int count; count = 1; d1 = count * 10; count = count + 1; d2 = count * 10; count = count + 1; d3 = count * 10; count = count + 1; printf("count = %d\n", count); printf("d1 = %d\n", d1); printf("d2 = %d\n", d2); printf("d3 = %d\n", d3); } /* main */

count=4 d1=10 d2=20 d3=30

What is the difference between a declaration and an initialization? [NOTE: This question is NOT about how you can tell what a declaration statement declares.]

declaration is when you create a variable, initialization is when you declare a variable and assign it a value

What is the difference between dividing an int by an intand dividing a float by a float? [NOTE: This question is NOT about how you can tell what a declaration statement declares.]

dividing int by an int rounds the answer ignoring the decimal place and gives the output as an integer, dividing float by a float outputs answer in a floating data type with decimal places.

What's an IMPORTANT difference between dividing an int by an int and dividing a float by a float? (NOTE: How something is declared ISN'T an acceptable answer to this question.)

dividing int by int is truncated; dividing float by float is like mathematics

Convert the following for loop into a count-controlled while loop. for (element = first_element; element < number_of_elements; element++) { product = product * array[element]; } /* for element */

element = first_element; while (element < number_of_elements) { sum = sum + array[element]; element++; } /* while (element < number_of_elements) */

How many values does a variable have at any given moment in runtime?

exactly one

Suppose an if block has an if clause and one else ifclause but no else clause. When the if block is encountered, HOW MANY OF ITS CLAUSES will be executed? Be very specific.

exactly one

In C, how can you tell whether a numeric literal constant represents a float value? [NOTE: You may give an example.]

float is in front of the decimal point

in a for loop, how can you tell whether the counter variable will increase or decrease?

if there is a + or a -

What is standard input?

input devices transport data into keyboard.

How can you tell whether a particular declaration statement declares an array variable? NOTE: You may give an example.

int array[size]; We can have int array vars

Give the sequence of a declaration statement followed by an assignment statement that corresponds to your previous answer.

int x; x=5;

Give an example of an initialization statement.

int x=5;

What's an IMPORTANT difference between dividing an int by a float and dividing a float by a float? (NOTE: How something is declared ISN'T an acceptable answer to this question.)

integer returns full value, in skips decimal

In a for loop, how can you tell what the counter variable is?

it is in the outer for block } ex. /* for*/

When data and instructions reside in the following kind of storage, when are they expected to be used? Registers Secondary storage

location where data and instructions are while being used now. data that will be used in the future

What is the difference between a named constant and a literal constant? [NOTE: This question is NOT about how you can tell what a declaration statement declares.]

named constants have names, literal constants express values literally

In a for loop, how many times is the loop initialization performed?

one time

In C, what kind of statement inputs from standard input?

scanf statement

What is the output of the following program?If the program won't compile, then mark WON'T COMPILEand explain.If the program produces no output, then mark NO OUTPUT and explain.If the program produces garbage (undefined) output, then mark GARBAGE and explain. #include <stdio.h> int main () { /* main */ int count; int sum; sum = 0; for (count = 1; count <= 4; count++) { sum = sum + count; } /* for count */ printf("sum = %d\n", sum); printf("count = %d\n", count); } /* main */

sum = 10 count = 5

What is the output? #include <stdio.h> int main () { /* main */ float sum; int count; sum = 0.0; count = 1; sum = sum + count; count = count + 1; sum = sum + count; count = count + 1; sum = sum + count; count = count + 1; printf("sum = %f\n", sum); printf("count = %d\n", count); } /* main */

sum=6 count=4

What is the output? #include <stdio.h> int main () { /* main */ const int tcsh = 35; printf("tcsh = %d\n", tcsh); } /* main */

tcsh=35

What is the output? #include <stdio.h> int main () { /* main */ float tethys = 4.5; tethys = 22.75; printf("tethys = %f\n", tethys); } /* main */

tethys=22.75

If a variable has been declared but not initialized, and it has not yet been assigned a value nor had a value input into it, then what value does it have?

undefined or "garbage"

What's an IMPORTANT difference between a variable and a constant? (NOTE: How something is declared ISN'T an acceptable answer to this question.)

variables value can vary, constants value stays the same

What is the output? #include <stdio.h> int main () { /* main */ const float tiana = 400.5; tiana = 200.25; printf("tiana = %f\n", tiana); } /* main */

won't compile

Give an example of a declaration statement.

x=5

What is the output? #include <stdio.h> int main () { /* main */ const int i = 4; const int j = 0; const int k = 19; const int m = 10; float h = 44.25; float y; y = k / m / (i + j * h); printf("y = %f\n", y); } /* main */

y = 0.25000

What is the output? #include <stdio.h> int main () { /* main */ int p = 8, q = 1000, r = 40, s = 200; int y; y = p + q + r + s; printf("y = %d\n", y); } /* main */

y=1248

What is the output? #include <stdio.h> int main () { /* main */ int h = 7, i = 53, j = 261, k = 32; int y; y = i / j + h / k; printf("y = %d\n", y); } /* main */

z=0


संबंधित स्टडी सेट्स

Chapter 6: Skeletal System: Bones and Bone Tissue

View Set

Chapter 6: Adolescence: Cognitive and Social Development

View Set

ACC 301 Ch.2 Smartbook Questions

View Set

Financial Accounting 2301 Quiz D

View Set

Chapter 5: Membrane Structure, Synthesis, and Transport Assignment

View Set

Leadership, Delegation, Priority client care

View Set

Chapter 10- Performance Nutrition

View Set