MBOSE Class IX Computer Science · Chapter 12
Programming in C
Opening soonHow to plan a solution with an algorithm and a flowchart, and how to write, run and read simple C programs with input, output, operators, decisions and loops.
17 lessons · 103 practice questions
What this chapter covers
- Problem solving
- Algorithms
- Flowcharts and their symbols
- History and features of C
- Structure of a C program
- Header files
- Main()
- Comments
- Printf() and scanf()
- Format specifiers
- Keywords and identifiers
- Constants and variables
- Data types (int, float, char, double)
- Arithmetic, relational, logical, assignment, increment and decrement operators
- If and if-else
- For and while loops
Key terms
- algorithm
Meaning: finite set of clear, step-by-step instructions
Example: steps to find an average
- flowchart
Meaning: diagram of an algorithm with standard symbols
- terminal
Meaning: oval symbol for Start and Stop
- decision box
Meaning: diamond with Yes/No exits
Example: Is A > B?
- debugging
Meaning: finding and correcting errors
- C
Meaning: language by Dennis Ritchie, Bell Labs, 1972
- header file
Meaning: file of library declarations, included with
#includeExample:
stdio.h- main()
Meaning: the function where every C program starts
Example:
int main()- comment
Meaning: note ignored by the compiler
Example:
/* … */,//- printf() / scanf()
Meaning: shows output / reads input
- format specifier
Meaning: code for the type of a value
Example:
%d,%f,%c,%lf- escape sequence
Meaning: special character code
Example:
\n,\t
Important questions with answers
10 of the 103 questions on this chapter, solved.
Question 1 · Multiple choice · 1 mark
A finite set of clear, step-by-step instructions for solving a problem is called
- (a) a flowchart
- (b) an algorithm
- (c) a compiler
- (d) a header file
Answer: (b) an algorithm
A flowchart is a diagram of an algorithm.
Question 2 · Multiple choice · 1 mark
Which of the following is a correct multi-line comment in C?
- (a)
<!-- note --> - (b)
/* note */ - (c)
## note ## - (d)
(* note *)
Answer: (b)
/* note *///starts a single-line comment.- (a)
Question 3 · Multiple choice · 1 mark
The data type used to store 45.75 is
- (a) char
- (b) float
- (c) int
- (d) void
Answer: (b) float
It has a decimal part; double also works.
Question 4 · Multiple choice · 1 mark
If
x = 4, then aftery = x++ + 1;the values are- (a) x = 5, y = 5
- (b) x = 4, y = 5
- (c) x = 5, y = 6
- (d) x = 4, y = 6
Answer: (a) x = 5, y = 5
Postfix uses the old value 4, then x becomes 5.
Question 5 · Assertion and reason · 1 mark
Assertion (A): Every C program must have a main() function.
Reason (R): A C program starts running from main().
- (a) Both A and R are true, and R is the correct explanation of A.
- (b) Both A and R are true, but R is not the correct explanation of A.
- (c) A is true, but R is false.
- (d) A is false, but R is true.
Answer: (a) Both A and R are true, and R is the correct explanation of A.
Without main() the program has no starting point.
Question 6 · Short answer · 2 marks
What is problem solving in computer science?
Answer
Working out the step-by-step solution of a problem — understanding it, planning it as an algorithm or flowchart, coding, testing and documenting — so that a computer can carry it out.
Question 7 · Short answer · 2 marks
Distinguish between
/and%with an example.Answer
/gives the quotient:17 / 5is 3 with integers.%gives the remainder:17 % 5is 2.Question 8 · Short answer · 3 marks
Explain the four basic data types of C with their sizes.
Answer
int: whole numbers, 4 bytes (2 in Turbo C). float: decimal numbers, 4 bytes. double: decimal numbers with more precision, 8 bytes. char: one character in single quotes, 1 byte.
Question 9 · Long answer · 5 marks
What is a flowchart? Explain the flowchart symbols and draw a flowchart to find the sum and average of three numbers.
Answer
A flowchart is a diagram of an algorithm drawn with standard symbols. Oval: Start/Stop. Parallelogram: input/output. Rectangle: process. Diamond: decision. Arrows: flow. Circle: connector. Flowchart: Start → Read A, B, C → SUM = A + B + C → AVG = SUM ÷ 3 → Print SUM, AVG → Stop (Fig. 12.2).
Question 10 · Long answer · 5 marks
Write a C program to read marks and print "Pass" if the marks are 33 or more, otherwise "Fail". Draw its flowchart.
Answer
#include <stdio.h> int main() { int marks; printf("Enter marks: "); scanf("%d", &marks); if (marks >= 33) { printf("Pass\n"); printf("Well done!\n"); } else { printf("Fail\n"); printf("Try again.\n"); } return 0; }Flowchart: Start → Read MARKS → "Is MARKS ≥ 33?" → Yes: Print Pass; No: Print Fail → Stop.
Study the whole chapter
17 step-by-step lessons, all 103 practice questions with hints, flashcards and mock tests for MBOSE Class IX Computer Science.