0% found this document useful (0 votes)
56 views4 pages

Assignment1 July2024

nptel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views4 pages

Assignment1 July2024

nptel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Problem Solving through Programming in C

Week 01 Assignment Solution

1. Which of the following is a valid C variable name?

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).

3. What is the purpose of the #include directive in a C program?

a) To include a library file.


b) To include a library file.
c) To define a constant.
d) To start the main function.

Answer: a) To include a library file.

Explanation: The #include directive is used to include the contents of a file or library into the program.

4. Which of the following correctly describes the purpose of a compiler in C?

a) To execute the program line by line.


b) To convert source code into machine code.
c) To provide a runtime environment for program execution.
d) To interpret and run the program interactively.

Answer: b) To convert source code into machine code.

Explanation: A compiler translates the entire source code of a program into machine code, which can
then be executed by the computer.

5. Which of the following is true about the execution nature of C programs?

a) C programs are executed in an event-based manner.


b) C programs are executed concurrently.
Problem Solving through Programming in C
Week 01 Assignment Solution

c) C programs are executed in a multi-threaded manner.


d) C programs are executed sequentially.

Answer: d) C programs are executed sequentially.

Explanation: By default, C programs execute statements sequentially, one after the other, unless control
flow statements (like loops or conditionals) alter this sequence.

6. In C programming, what is the best way to comment multiple lines?

a) Using // at the beginning of each line.


b) Enclosing the comments between /* and */.
c) Using # at the beginning of each line.
d) Enclosing the comments between { and }.

Answer: b) Enclosing the comments between /* and */.

Explanation: In C, multi-line comments are enclosed between /* and */.

7. Which of the following is a characteristic of the ASCII standard?

a) It supports encoding for all the world's languages.


b) It uses 16-bit encoding for characters.
c) It is a 7-bit character encoding standard.
d) None of the above.

Answer: c) It is a 7-bit character encoding standard.

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.

8. Which of the following statements is true regarding variable declaration in C?

a) Variables can be declared at any point in the program.


b) Variables must be declared before they are used.
c) Variables are automatically initialized to zero.
d) Variable names can start with a digit.

Answer: b) Variables must be declared before they are used.

Explanation: In C, variables must be declared before they are used in the code.
Problem Solving through Programming in C
Week 01 Assignment Solution

9. What will be the output of the flowchart given below?

a) 4
b) 8
c) 16
d) 20

Solution: (c) b=a+b=5,b=a*b+ b/5=3*5 + 5/5=15 +1= 16

10. The output of the following algorithm is

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.

You might also like