Assignment1 July2024
Assignment1 July2024
a) 2variable
b) variable_2
c) variable-2
d) variable.2
Answer: b) variable_2
Explanation: In C, variable names must start with a letter or an underscore, followed by letters, digits,
or underscores. 'variable_2' follows these rules, whereas '2variable' starts with a digit, and 'variable-2'
and 'variable.2' contain invalid characters.
2. Which of the following functions is used to read a single character from the keyboard in C?
a) printf()
b) scanf()
c) getchar()
d) puts()
Answer: c) getchar()
Explanation: The getchar() function reads the next character from the standard input (keyboard).
Explanation: The #include directive is used to include the contents of a file or library into the program.
Explanation: A compiler translates the entire source code of a program into machine code, which can
then be executed by the computer.
Explanation: By default, C programs execute statements sequentially, one after the other, unless control
flow statements (like loops or conditionals) alter this sequence.
Explanation: ASCII (American Standard Code for Information Interchange) is a 7-bit character
encoding standard that represents text in computers and other devices that use text.
Explanation: In C, variables must be declared before they are used in the code.
Problem Solving through Programming in C
Week 01 Assignment Solution
a) 4
b) 8
c) 16
d) 20
a) 21
b) 28
c) 30
d) 40
Problem Solving through Programming in C
Week 01 Assignment Solution
Solution: (b) The flowchart finds the sum of first 7 natural numbers. Hence, the right answer is 28.