Kami+Export+-+HW1+(1)

pdf

School

University of Massachusetts, Lowell *

*We aren’t endorsed by this school

Course

COMP 1010

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

8

Uploaded by BrigadierScience12941

Report
Computing I: Homework Packet 1 Name___________________________________ SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question. 1) The format specifier used to tell printf to expect a double precision floating point number is a percent sign followed by the character(s) ________. 1) 2) The portion of the printf function call within the double quotes is called the ________. 2) 3) ________ is the decimal number 42 converted to an 8 bit binary number using 2's complement notation. 3) 4) Each time a loop body executes is known as an ________. 4) 5) int myValue; is called a ________. 5) 6) What is the opposite of ( x < 20 && x > 12)? 6) 7) Is printf used for input or output? 7) 8) ________ is the decimal number associated with the ASCII character '0' 8) 9) What is the correct conditional statement to determine if x is between 19 and 99? 9) 10) When must we use braces to define the body of a conditional expression? 10) 11) The format specifier used to tell printf to expect an integer is a percent sign followed by the character (s)________. 11) 12) Write the loop condition to continue a while loop as long as x is negative. 12) 13) if - else statements that are inside other if - else statements are said to be ________. 13) 14) ________ is the decimal number - 42 converted to an 8 bit binary number using 2's complement notation. 14) 15) In a compound logical and (&&) expression, the evaluation of the expression stops once one of the terms of the expression is false. This is known as ________ evaluation. 15) 16) The braces for a loop define the ________ of the loop. 16) 17) A loop that always executes the loop body at least once is known as a ________ loop. 17) 1 Computing l: Homework Packet 1 Name SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question. 1) The format specifier used to tell printf to expect a double precision floating point number is a percent sign followed by the character(s) 2) The portion of the printf function call within the double quotes is called the 3) is the decimal number 42 converted to an 8 bit binary number using 21s complement notation. 4) Each time a loop body executes is known as an 5) int myValue; is called a 6) What is the opposite of (x < 20 && x > 12)? 7) Is printf used for input or output? 8) is the decimal number associated with the ASCII character '0' 9) What is the correct conditional statement to determine if x is between 19 and 99? 10) When must we use braces to define the body of a conditional expression? 11) The format specifier used to tell printf to expect an integer is a percent sign followed by the character (s) 12) Write the loop condition to continue a while loop as long as x is negative. 13) if-else statements that are inside other if-else statements are said to be 14) is the decimal number -42 converted to an 8 bit binary number using 2's complement notation. 15) In a compound logical and (&&) expression, the evaluation of the expression stops once one of the terms of the expression is false. This is known as 16) The braces for a loop define the of the loop. 17) A loop that always executes the loop body at least once is known as a evaluation. loop. l) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) 13) 15) 17) %lf Format String 00101010 iteration variable declaration (x >= 20 || x <= 12) Output 48 (x > 19 && x < 99) multiple statements %d while (x < 0) nested 11010110 short-circuit scope do-while int x; x = x + 30;
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 18) What is the value of x after the following statements? double x; x = 15/4; 18) A) 4.0 B) 60 C) 3.75 D) 3.0 19) What is the output of the following code? int value; value = 33; printf("value\n"); 19) A) value B) value\n C) 33 D) garbage 20) What is the value of x after the following statement? double x; x = 3.0/4.0 + (3 + 2)/5; 20) A) 5.75 B) 4.75 C) 3.75 D) 1.75 21) Given the following code fragment, and an input value of 5, what is the output? int x; printf("Enter a value\n"); scanf("%d", &x); if( x < 3) { printf("small\n"); } else { if( x < 4) { printf("medium\n"); } else { if( x < 6) { printf("large\n"); } else { printf("giant\n"); } } } 21) A) medium B) giant C) large D) small 22) Another way to write the value 3452211903 is ________. 22) A) 3.452211903x09 B) 3.452211903e09 C) 3452211903e09 D) 3.452211903e - 09 2 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 18) What is the value of x after the following statements? double x; x = 15/4; A) 4.0 B) 60 19) What is the output of the following code? int value; value = 33; printf("value\n"); A) value B) value\n 20) What is the value of x after the following statement? double x; x = 3.0/4.0 + (3 + 2)/5; A) 5.75 B) 4.75 C) 3.75 C) 33 C) 3.75 21) Given the following code fragment, and an input value of 5, what is the output? int x; printf("Enter a value\n"); scanf("%d" &x); if(x < 3) printf("small\n"); if( x < 4) printf("medium\n"); if(x < 6) printf("large\n"); else printf("giant\n"); A) medium B) giant D) 3.0 D) garbage D) 1.75 D) small 18) 19) 20) 21) 22) 22) Another way to write the value 3452211903 is C) 3452211903e09 C) large B) 3.452211903e09 D) 3.452211903+09 2 A As the console output wont show the nextline D D C b
23) Given the following code fragment and the input value of 2.0, what output is generated? double tax; double total; printf("enter the cost of the item\n"); scanf("%lf", &total); if ( total >= 3.0) { tax = 0.10; printf("%f\n", total + (total * tax)); } else { printf("%f\n", total); } 23) A) 2.0 B) 4.4 C) 2.2 D) 3.1 24) What is the output of the following code fragment? int x = 0; while( x < 5) printf("%d\n", x); x ++ ; printf("%d\n", x); 24) A) 5 B) 0 C) 4 D) an unending list of zeroes 25) Given the following code fragment, what is the output? int x = 5; if( x > 5) printf("x is bigger than 5. "); printf("That is all. "); printf("Goodbye\n"); 25) A) x is bigger than 5. That is all B) Goodbye C) That is all. Goodbye D) x is bigger than 5 26) What is the value of x after the following statement? double x; x = 3.0/4.0 + 3 + 2/5; 26) A) 5.75 B) 1.75 C) 3.75 D) 4.75 27) Given the following code fragment, which of the following expressions is always true? int x; scanf("%d", &x); 27) A) if( x < 3) B) if( x = 1) C) if( x == 1) D) if((x/3) > 1) 28) What is the value of x after the following statements? int x; x = x + 30; 28) A) 33 B) garbage C) 0 D) 30 3 23) Given the following code fragment and the input value of 2.0, what output is generated? double tax; double total; printf("enter the cost of the item\n"); scanf("%lf", &total); if ( total >= 3.0) tax = 0.10; printf("%f\n", total + (total * tax)); printf("%f\n", total); A) 2.0 B) 4.4 24) What is the output of the following code fragment? intx= 0; while(x < 5) printf("%d\n", x); printf("%d\n", x); C) 2.2 D) 3.1 D) an unending list of zeroes 25) Given the following code fragment, what is the output? intx= 5; if(x > 5) printf("x is bigger than 5. "); printf("That is all. "); printf("Goodbye\n"); A) x is bigger than 5. That is all C) That is all. Goodbye 26) What is the value of x after the following statement? double x; x = 3.0/4.0 + 3 + 2/5; A) 5.75 B) 1.75 B) Goodbye D) x is bigger than 5 C) 3.75 D) 4.75 27) Given the following code fragment, which of the following expressions is always true? int x; scanf("%d" &x); C) if( x 28) What is the value of x after the following statements? 23) 25) 26) 27) 28) int x; x = x + 30; A) 33 B) garbage D) 30 3 A D Reason is because of bad code provided. C Again reason is bad coding c B B
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
29) What is the value of x after the following statements? int x, y, z; y = 10; z = 3; x = y * z + 3; 29) A) 33 B) 30 C) 60 D) garbage 30) What is the output of the following code? int value; value = 33; printf("%d\n", value); 30) A) "%d\n",value B) 33\n C) 33 D) value\n 31) Given the following code fragment and the input value of 4.0, what output is generated? double tax; double total; printf("enter the cost of the item\n"); scanf("%lf", &total); if ( total >= 3.0) { tax = 0.10; printf("%f\n", total + (total * tax)); } else { printf("%f\n", total); } 31) A) 3.3 B) 4.4 C) 3 D) 4.0 32) Which of the following is not a valid identifer? 32) A) myInteger B) total3 C) myInt D) return 33) Given the following code fragment, what is the final value of y? int x, y; x = - 1; y = 0; while(x < 3) { y += 2; x += 1; } 33) A) 2 B) 6 C) 8 D) 10 34) Which of the following lines correctly reads a value from the keyboard and stores it in the integer variable named myInt? 34) A) scanf("%d", myInt); B) scanf("%d\n", myInt); C) scanf("myInt"); D) scanf("%d", &myInt); 4 29) What is the value of x after the following statements? int x, y, z; A) 33 B) 30 30) What is the output of the following code? int value; value = 33; printf("%d\n", value); A) "%d\n",value B) 33\n C) 60 C) 33 D) garbage D) value\n 31) Given the following code fragment and the input value of 4.0, what output is generated? double tax; double total; printf("enter the cost of the item\n"); scanf("%lf", &total); if ( total >= 3.0) tax = 0.10; printf("%f\n", total + (total * tax)); printf("%f\n", total); A) 3.3 B) 4.4 32) Which of the following is not a valid identifer? A) mylnteger B) tota13 C) mylnt 33) Given the following code fragment, what is the final value of y? int x, y; while(x < 3) D) 4.0 D) return D) 10 34) Which of the following lines correctly reads a value from the keyboard and stores it in the integer 29) 30) 31) 32) 33) 34) variable named mylnt? A) scanf("%d" mylnt); C) scanf("mylnt"); B) scanf("%d\n", mylnt); D) scanf("%d" &mylnt); 4 b d c A C D
35) What is the value of x after the following statements? int x; x = 15/4; 35) A) 15 B) 3.75 C) 4 D) 3 36) Which of the following statements is NOT legal? 36) A) char ch = "cc"; B) char ch = '0'; C) char ch = 65; D) char ch = 'b'; 37) What is the correct way to write the condition y < x < z? 37) A) ((y < x) && (x < z)) B) (y < x < z) C) ((y > x) A (y < z)) D) ( (y < x) && z) 38) Given the following code fragment, what is the final value of y? int x, y; x = - 1; y = 0; while(x <= 3) { y += 2; x += 1; } 38) A) 8 B) 6 C) 10 D) 2 39) Which of the following is a valid identifier? 39) A) 3 - com B) dollar$ C) 3com D) three_com E) 3_com 40) What is the value of x after the following statements? int x; x = 0; x = x + 30; 40) A) 0 B) 30 C) garbage D) 33 41) Given the following code fragment, and an input value of 3, what is the output that is generated? int x; printf("Enter a value\n"); scanf("%d", &x); if(x = 0) { printf("x is zero\n"); } else { printf("x is not zero\n"); } 41) A) x is not zero. B) unable to determine C) x is zero. D) x is 3. 42) What is the value of x after the following statements? int x; x = 15 %4; 42) A) 3 B) 3.75 C) 15 D) 4 5 35) What is the value of x after the following statements? int x; x = 15/4; A) 15 B) 3.75 36) Which of the following statements is NOT legal? A) char ch - "cc"; B) char ch = C) char ch = 65; 37) What is the correct way to write the condition y < x < z? 38) Given the following code fragment, what is the final value of y? int x, y; while(x 3) 39) Which of the following is a valid identifier? A) 3.com B) dollar$ C) 10 C) 3com D) three.com 40) What is the value of x after the following statements? int x; B) 30 C) garbage D) char ch = E) 3.com D) 33 41) Given the following code fragment, and an input value of 3, what is the output that is generated? 35) 36) 37) 38) 39) 40) 41) int x; printf("Enter a value\n"); scanf("%d" &x); if(x = 0) printf("x is zero\n"); printf("x is not zero\n"); A) x is not zero. C) x is zero. 42) What is the value of x after the following statements? int x; x = 15 0/04; B) unable to determine B) 3.75 C) 15 5 d c a a b d c a
43) Given the following code fragment, and an input value of 0, what is the output that is generated? int x; printf("Enter a value\n"); scanf("%d", &x); if(x = 0) { printf("x is zero\n"); } else { printf("x is not zero\n"); } 43) A) unable to determine B) x is zero. C) x is not zero. D) x is 0. 44) Executing one or more statements one or more times is known as 44) A) selection. B) sequence. C) algorithm. D) iteration. 45) What is the output of the following code? printf( "This is a \\" ); 45) A) Nothing, it is a syntax error. B) "This is a \\" C) This is a D) This is a \ 46) What is the final value of x after the following fragment of code executes? int x = 0; do { x ++ ; }while(x > 0); 46) A) infinite loop. B) 9 C) 8 D) 10 E) 11 47) What is the value of x after the following statements? double x; x = 0; x += 3.0 * 4.0; x -= 2.0; 47) A) 12.0 B) 22.0 C) 10.0 D) 14.0 TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false. 48) Variable names may begin with a number. 48) 49) Loops are used when we need our program to make a choice between two or more things. 49) 50) After the following code fragment, x has the value of 3. int x = 3; 50) 6 43) Given the following code fragment, and an input value of 0, what is the output that is generated? int x; printf("Enter a value\n"); scanf("%d" &x); if(x = 0) printf("x is zero\n"); printf("x is not zero\n"); A) unable to determine C) x is not zero. B) x is zero. D) x is O. 44) Executing one or more statements one or more times is known as A) selection. B) sequence. 45) What is the output of the following code? printf( "This is a ); A) Nothing, it is a syntax error. C) This is a C) algorithm. B) "This is a D) This is a \ 46) What is the final value of x after the following fragment of code executes? intx=0; do A) infinite loop. D) 10 E) 11 47) What is the value of x after the following statements? double x; x 3.0 * 4.0; x-=20 A) 12.0 B) 22.0 C) 10.0 D) iteration. D) 14.0 TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false. 48) Variable names may begin with a number. 49) Loops are used when we need our program to make a choice between two or more things. 50) After the following code fragment, x has the value of 3. intx=3; 6 43) 44) 45) 46) 47) 48) 49) 50) 3 f f c a d b b
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
51) The integer 0 is considered true. 51) 52) The body of a while loop may never execute. 52) 53) The body of a do - while loop always executes at least once. 53) 54) Every line in a program should have a comment. 54) 55) If x has the value of 3, y has the value of - 2, and w is 10, is the following condition true or false? if( x < 2 && w < y) 55) 56) The opposite of (x > 3 && x < 10) is (x < 3 && x > 10). 56) 57) The opposite of less than is greater than. 57) 58) It is legal to declare more than one variable in a single statement. 58) Sample Exam Questions and Extra Practice (Canning Problems). You do not have to turn in solutions to these questions. 59) Canning Problem 12: Write a C program that reads a single integer number from the keyboard via the scanf function, determines if the number is either, positive, zero, or negative and then prints out a message such as: “ The number is positive .” or “ The number is zero .” or “ The number is negative .” 60) Canning Problem 11:Write a C program that reads a single integer number from the keyboard via the scanf function, determines if the number is equal to zero or not, and then either prints out: “The number is equal to zero.” or “The number is not equal to zero.” 61) Canning Problem 7: Write a C program that reads a number from the keyboard via the scanf function, and then prints the message The number is bigger than 100 if it is. If the number is 100 or less than 100 then you should print out the message: The number is not bigger than 100. Make certain that your code looks good. No ragged indents. 62) Write the section of code required to print the sum of the first n integers (starting with 1)where n is a positive number entered from the keyboard by the user. You may assume you have all required include directives and that the user will not enter a negative number. 63) Canning Problem 2: Write a C program that prints out the value 6. I want you to use the %d format code. Your textbook explains about format codes. 64) Canning Problem 1: Write a C program that prints out the message Hello World . 65) Canning Problem 4: Write a C program that reads an integer value from the keyboard via the scanf function and then prints it back onto the screen. You should know that scanf seeks an address expression. For example, &n is an address expression. You should also know that scanf returns a value. It is either the number of successful conversions or an error code that is typically EOF. Please read about the scanf function in Appendix D of your textbook. 66) Canning Problem 3: Write a C program that prints out the single character P. I want you to use the %c format code. 67) Write the section of code required to print the integers from - 100 to positive 100 on the screen including the endpoints where one number is printed per line. You may assume you have all required include directives. 7 51) The integer 0 is considered true. 52) The body of a while loop may never execute. 53) The body of a do-while loop always executes at least once. 54) Every line in a program should have a comment. 55) If x has the value of 3, y has the value of -2, and w is 10, is the following condition true or false? if(x < 2 w < y) 56) The opposite of (x > 3 && x < 10) is (x < 3 && x > 10). 57) The opposite of less than is greater than. 58) It is legal to declare more than one variable in a single statement. 51) 52) 53) 54) 55) 56) 57) 58) Sample Exam Questions and Extra Practice (Canning Problems). You do not have to turn in solutions to these questions. 59) Canning Problem 12: Write a C program that reads a single integer number from the keyboard via the scan/ function, determines if the number is either, positive, zero, or negative and then prints out a message such as: "The number is positive." or "The number is zero." or "The number is negative." 60) Canning Problem 1 1 : Write a C program that reads a single integer number from the keyboard via the scanffunction, determines if the number is equal to zero or not, and then either prints out: "The number is equal to zero. " or "The number is not equal to zero. 61) Canning Problem 7: Write a C program that reads a number from the keyboard via the scanffunction, and then prints the message The number is bigger than 100 if it is. Ifthe number is 100 or less than 100 then you should print out the message: The number is not bigger than 100. Make certain that your code looks good. No ragged indents. 62) Write the section of code required to print the sum of the first n integers (starting with l)where n is a positive number entered from the keyboard by the user. You may assume you have all required include directives and that the user will not enter a negative number. 63) Canning Problem 2: Write a C program that prints out the value 6. I want you to use the %d format code. Your textbook explains about format codes. 64) Canning Problem l: Write a C program that prints out the message Hello World. 65) Canning Problem 4: Write a C program that reads an integer value from the keyboard via the scanffunction and then prints it back onto the screen. You should know that scanfseeks an address expression. For example, &n is an address expression. You should also know that scanfreturns a value. It is either the number of successful conversions or an error code that is typically EOF. Please read about the scanffunction in Appendix D of your textbook. 66) Canning Problem 3: Write a C program that prints out the single character P. I want you to use the %c format code. 67) Write the section of code required to print the integers from -100 to positive 100 on the screen including the endpoints where one number is printed per line. You may assume you have all required include directives. 7 f t t f f t t t
68) Write a complete program that will ask the user for two values of type double and then print the average on the screen with a message that says whether the average is a positive number or a negative number. 69) Canning problem 5: Write a C program that reads two integer values from the keyboard via the scanf function, then adds them together, stores the result into a variable called sum, and then prints out the value of the variable sum. I want you to use a single call to scanf. Do not use two separate calls to scanf. 8 68) Write a complete program that will ask the user for two values of type double and then print the average on the screen with a message that says whether the average is a positive number or a negative number. 69) Canning problem 5: Write a C program that reads two integer values from the keyboard via the scan/ function, then adds them together, stores the result into a variable called sum, and then prints out the value of the variable sum. I want you to use a single call to scant Do not use two separate calls to scant 8