Intro. To CS - Previous Midterm Exams ANSWER KEYs (3 Exams - 2023)
Intro. To CS - Previous Midterm Exams ANSWER KEYs (3 Exams - 2023)
HELWAN NATIONAL UNIVERSITY – FACULTY OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY | COURSE CODE : COM-101
COURSE NAME : INTRODUCTION TO COMPUTER SCIENCE | COORDINATOR(S): DR. AHMED MADBOULY AND DR. AMR GHONEIM
Date: Wednesday, November 22rd, 2023 | MARKS: [ 20 ] | Time: [ 30 mins ]
1) Which of the following is a valid C identifier (variable name)? (a) id-1 (b) float (c) _float
(d) 1id (e) id#1
2) Which of the following C statements is used to read/input a double number from the user:
(a) scanf("%d", &x); (b) double x = 3.5; (c) x = 8.99;
(d) scanf( "%lf", &x ); (e) printf (“Enter a double number”, x);
3) A C program that prints three lines of output must contain three printf statements. (a) True
(e) False
4) The fifth generation of computers (Present Beyond) is based on: (a) Integrated Circuits.
(b) Transistors. (c) Artificial Intelligence. (d) Vaccum tubes. (e) None of the above.
5) _____ is a header file that contains information used by the compiler when compiling calls to
library functions (built-in functions) such as printf and scanf. (a) <stdio.h> (b) <io.h>
(c) <stdoi.h> (d) <stdlib.h> (e) <math.h>
6) Apple Vision Pro is Apple's first-ever 3D camera. Now you can capture photos and videos with
remarkable depth." This feature is an example of ____ devices. (a) Storage (b) Output
(c) Input (d) Processing (e) Communication
7) What is the problem with the following C statement: 100 = grade; (a) Nothing is wrong
with the statement. (b) 100 is not a reasonable grade. (c) Data types don't match. (d) 100 should be
in quotes. (e) Value on the left must be a variable name.
8) The part of an algorithm that is repeated for a number of times is classified as: (a) Iteration.
(b) Selection. (c) Sequence. (d) Reverse action. (e) Decision.
9) An ordered set of instructions that are carried out (performed) by a computer is called a:
(a) Machine. (b) Compiler. (c) Programming language. (d) Program. (e) Syntax.
Page 1 of 2
10) What component of the computer is correctly associated with the function it performs?
(a) Microprocessor: Storage. (b) Random Access Memory (RAM): Processing.
(c) ROM: Input. (d) Monitor: Output. (e) All of the above.
11) An Operating System is considered a: (a) System Software. (b) General-purpose Application.
(c) Special-Purpose Application. (d) Utility Program. (e) Library Program.
12) To declare two variables in the C language, it is written as: (a) char x; int y;
(b) char int x, y; (c) char x, int y; (d) x = ‘c’, y = 5; (e) All of the above.
13) A multiple-line comment in C source code begins with: (a) ; (b) @ (c) /* (d) // (e) #
14) In a C program, variables must only be declared inside the main function. (a) True (e) False
15) Consider the following code snippet, what will be the output of this code?
int x = 5;
int y = 10;
printf("%d %d\n", y, y);
(a) 5 10 (b) 10 5 (c) 10 10 (d) %d %d (e) None of the above.
16) Consider the following code snippet, what will be the output of this code?
char ch = '!';
printf("Character: %d\n", ch);
(a) Character: 33 (b) Character: %c (c) Character: ! (d) 5 (e) None of the above
17) Which of the following C statements requires error handling (to avoid a runtime error)?
(a) int x = 5; (b) printf("Hello, World!"); (c) int z = y * 2; (d) int a = 22 / b - 5; (e) None of the above.
18) What will be the output of the following C code if the input is 1234.4?
int num;
scanf("%d", &num);
printf("%d\n", num);
(a) 1234 (b) 1234.4 (c) num (d) %d (e) None of the above.
19) Enhancing the readability of a C program can be achieved through which of the following?
(a) Using meaningful names for variables and constants. (b) Using indentation and comments.
(c) Using consistent naming conventions. (d) All of the above.
20) The keyword used to transfer (hand over) control from a function back to the calling function
(or the operating system) is: (a) end. (b) return. (c) goto. (d) go back. (e) stop.
Page 2 of 2
Modelيجب تسليم ورقة األسئلة ليقوم المصحح بتحديد الـ
COURSE NAME : INTRODUCTION TO COMPUTER SCIENCE
COORDINATOR: DR. AMR S. GHONEIM
COURSE CODE : CS-111 [MAINSTREAM PROGRAMME] MARKS: [ 20 ]
Date: Thursday, November 16th, 2023 Time: [ 30 mins ]
Page 1 of 2
13) Consider the following code snippet, what will be the
output of this code?
char ch_1 = '\0', ch_2 = '\a', ch_3 = '\t', ch_4 = '\n';
printf("%d, %d, %d, %d\n", ch_1, ch_2, ch_3, ch_4);
(a) \0, \a, \t, \n (b) Nothing will be printed. (c) A syntax error; because some of the assigned
values are not characters. (d) 0, 7, 9, 10 (e) \0, [a beep sound], [a tab], [a new line]
14) What is the correct way to print the values of two variables, x and y, using the printf function
in C? (a) printf("x = %d y = %d", &x, &y); (b) printf("x = %d y = %d", x, y); (c) printf("x, y", x, y);
(d) printf("x, y", &x, &y); (e) printf("x = x, y = y");
15) Consider the following code snippet: char ch = 'A'; what is the physical address of the
memory location where ch is stored? (a) It is the name of the variable ch. (b) It is the value of
the variable ch. (c) It is the type of the variable ch. (d) It is the actual location in memory where
the data associated with ch is stored. (e) None of the above.
16) What will be the result of the following C code if the input is: 1234?
char ch; scanf("%c", &ch); printf("%c\n", ch); (a) It will print the character ‘1’.
(b) It will print the string “1234”. (c) It will cause a compilation error. (d) None of the above.
17) Information represents the individual scores of students in different courses, while data is the
organized presentation of these scores, providing a clear picture of each student's
performance. (a) True. (e) False.
18) Consider the following C code snippet, which of the following do not exist in the compiled
program: (a) RADIUS. (b) area. (c) circumference. (d) PI. (e) Both PI and RADIUS.
#define PI 3.14
int main () { const int RADIUS = 10; float area = PI * RADIUS * RADIUS;
float circumference = 2 * PI * RADIUS; }
19) What is the output of this code? int x = 6, y = 4; printf("%d", x | y);
(a) 10 (b) 6 (c) 4 (d) 2 (e) None of the above.
20) "This is visionOS, Apple's first-ever spatial operating system." VisionOS is considered a:
(a) System Software. (b) General-purpose Application. (c) Special-Purpose Application. (d) Utility
Program. (e) Library Program.
21) Which of the following C statements will result in a syntax error: (a) double x, X;
(b) char c = ‘\n’; (c) const float PI 3.14 (d) double z = 11; (e) All of the above.
Page 2 of 2
Make-Up Midterm Exam
COURSE NAME : INTRODUCTION TO COMPUTER SCIENCE
COURSE CODE : CS-111 | COM-101 MARKS: [ 20 ] Time: [ 30 mins ]
Choice Input: Prompt the user to choose a discount and read their choice.
Error Handling: Ensure that the choice is within the range of 1 to NUM_OPTIONS (using an if
statement). If the user's input is NOT a valid choice, print an error message: "Invalid choice. Exiting
program.", and exit the program while returning an error code of 1.
Price Input: Prompt the user to enter the original price of the item and read it.
Error Handling: Ensure that the original price is a positive value (using an if statement). If the
original price is NOT a valid positive value, the program prints an error message: "Invalid price.
Exiting program.", and exits while returning an error code of 1.
Discount Calculation: Calculate the discounted price based on the user's choice using only
conditional expressions (without using if statements, switch statements, or conditional/ternary
operators).
Result Display: Display the discounted price with exactly two decimal places.
Program Exit: Exit the program with a success code of 0.
Example:
Discount Options:
1. 10%
2. 20%
3. 30%
Choose a discount (1-3): 1
Enter the original price: 100
Discounted Price: $90.00
_________________________________________________________________________________
Page 1 of 2
#include <stdio.h>
#define NUM_OPTIONS 3
int main() {
float originalPrice, discountedPrice;
int discountChoice;
Page 2 of 2