Class 9 Computer Science Chapter 9 Exploring C Programming Language

Class 9 Computer Science Chapter 9 Exploring C Programming Language Question Answer, Computer Science Class 9 Solutions, NCERT Class 9 Computer Science Chapter 9 Exploring C Programming Language Question Answer for each chapter is provided in the list so that you can easily browse throughout different chapters SCERT Class 9 Computer Science Chapter 9 Exploring C Programming Language Solutions and select needs one.

Join Telegram channel

Class 9 Computer Science Chapter 9 Exploring C Programming Language

Also, you can read the SCERT book online in these sections Solutions by Expert Teachers as per SCERT (CBSE) Book guidelines. NCERT Solution of Class 9 Computer Science Chapter 9 Exploring C Programming Language is part of AHSEC All Subject Solutions. Here we have given Class 9 Computer Science Chapter 9 Exploring C Programming Language Notes for All Subjects, You can practice these here in SEBA Class 9 Computer Science.

Exploring C Programming Language

Chapter – 9

COMPUTER SCIENCE

Important Terms (Basic Concepts)

● C-Keywords: keywords are predefined, reserved words used in programming that have special meanings to the compiler.

● Variables: A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines the size.

● Data Types: A data type or simply type is an attribute of data which tells the compiler or interpreter how the programmer intends to use the data.

● Operators: An operator is a symbol that operates on a value or a variable.

● Conditional Statements: Conditional Statements in C programming are used to make decisions based on the conditions.

● loop: A loop is a programming structure that repeats a sequence of instructions until a specific condition is met.

● If-else: An if-else  statement can evaluate almost all the types of data such as integer, floating-point, character, pointer, or boolean.

● Switch: Switch statement in C tests the value of a variable and compares it with multiple cases.

● Sizeof(): The sizeof is a keyword, but it is a compile-time operator that determines the size, in bytes, of a variable or data type.

TEXTUAL QUESTIONS AND ANSWERS

OBJECTIVE TYPE QUESTIONS

1. Fill in the blanks.

(a) Identifiers in C programming language start with _____.

Ans. letter.

(b) Break is a keyword in C _____. (True/False)

Ans. True.

(c) A variable in C can store more than one value at a time _____. (True/False)

Ans. True.

(d) An integer variable typically reserves _____ bytes in memory.

Ans. 4.

(e) Built-in function used to accept user input from the keyboard is ____.

Ans. scanf().

(f) Format specifier for accepting value from keyboard for an integer variable is  _____.

Ans. %d.

(g) Every operator in C requires exactly two operands ____. (True/False)

Ans. False.

(h) ____ sign is used to indicate reminder operation in C.

Ans. % .

(i) To compare two float variables in C, we can use _____ statement.

Ans. if.

(j) When we need to select a set of statements for execution in a C program based on some integral value, a good choice can be to use  ____ construct.

Ans. switch ( ).

DESCRIPTIVE TYPE QUESTIONS

2. Short answer questions.

1. If we need to execute many statements when an if condition in C returns true, how can we write them? Write a code segment.

Ans. If we need to execute many statements when an if condition in C returns true, we put the statements inside two curly braces.

Code segment is shown below: 

If (num1> num2)

greater = num1;

Printf(“\n First number is greater than the second number”);

}

2. List five commonly used operators of C programming language with their meaning.

Ans. Commonly used operators of C programming languages are listed below: 

● Arithmetic Operators: These are the operators used to perform arithmetic/mathematical operations on operands. Examples : (+,-,*,/,%,++,-).

● Relational Operators: These are used for comparison of the values of two operands.

For example, checking if one operand is equal to the other operand or not, an operand is greater than the other operand or not etc. Some of the relational operators are (==, >=, <= ).

● Logical Operators: Logical Operators are used to combine two or more conditions/constraints or to complement the evaluation of the original condition in consideration. The result of the operation of a logical operator is a boolean value either true or false. For example, the logical AND represented as ‘&&’ operator in C returns true when both the conditions under consideration are satisfied. Otherwise it returns false. Therefore, a && b returns true when both a and b are true (i.e. non-zero).

● Bitwise Operators: The Bitwise Operators are used to perform bit-level operations on the operands. For example, the Bitwise AND represented as & operator in C takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.

● Assignment Operators: Assignment Operators are used to assign values to a variable. The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value. Some of the assignment operators are =, +=, -=, *=, etc.

3. The scanf statement should always be preceded by a printf statement in C. Is it true? Explain briefly.

Ans. It is not necessary that scanf statement’ should always be preceded by a printf statement in C.

The printf () statement is written just to inform the user for entering the integer value. This is not a mandatory statement.

3. Programming assignments: 

1. Write a C program and try to declare variables of type int with the following variable names separately.

first_variable, second Variable, Third Variable, char, number, -, —, _x, 9months, blp24, 8724, dimatala, gogamukh??, I want to be a doctor. Report if any variable declarations are not permitted by the Compiler. Analyse the reasons (Hint : refer Section 9.1).

Ans. #include <stdio.h>

Int main( ) 

{

int first _variable;

int second Variable;

int Third Variable;

int number;

int blp24;

int dimatala;

}

The following variables are not allowed in C.

NameReason
charKey words are not allowed as variable.
-, —-, gogamukh??A variable name can only have letters (both uppercase and lowercase letters), digits and underscore.
_x, 9months, 8724Variable name must start with letter.
I want to be a doctorSpaces not allowed in variable name.

2. Write the following code segment inside the main() function of a C program and run it. Analyse the output. Relate the output with the concepts learned in Section 9.2 about the allocated space of a variable in computer memory.

int var = 7;

Printf (“The value of var is %d.”, var);

Printf (“The address of var in memory is %p.”, &var);

Ans. Output

Thus we can see from the output that %d format specifier is used to display the output of the variable (var) and %p is used to display the address of the variable (var).

3. Write the following code segment inside the main () function of a C program and run it. Analyse the output. Relate the output with the concepts learned in Section 9.2 about the allocated space of a variable in computer memory.

int p = 9;

printf(“Size of the variable p is %ld \n”, sizeof(p) );

Printf (“Size of an integer is %ld \n”, sizeof(int) );

printf(“Storage for the type of the variable p is %ld \n”, sizeof(typeof (p) ) );

Ans. Output

In C, sizeof() function determines the size of the expression or the data type specified in the number of char-sized storage units. The variable p is an integer so its size is 2 bytes but as it is a long integer is takes the size as 4 bytes. The format specifier %ld is long integer so the size of an integer is 4 bytes.

4. Write a C program to do the following.

(i) Declare three integer variables as int p = 9, q = 7, result = 0;

(ii) Display the value of the result variable after performing the following operations and storing the output of each operation in it.

p + q; p – q; p/q; p%q; p + q; (p & q); ( p &&& q);

(iii) Perform ++ result; result++; result – -; Display value of result at each step.

Ans. (i) #include<stdio.h>

int main()

{

int p = 9, q = 7, result = 0;

return 0;

}

(ii) Output

(iii) Program

#include<stdio.h>
int main()
{

int p = 9, q = 7, result = 0;

result = p+q;

printf(“\nThe value of p+q is %d”, ++result);

printf(“\nThe value of p+q is %d”, result++);

printf(“\nThe value of p+q is %d”, result- -);

result=p-q;

printf(“\nThe value of p-q is %d”,++result);

printf(“\nThe value of p-q is %d”, result++);

printf(“\nThe value of p-q is %d”, result- -);

result=p/q;

printf(“\nThe value of p/q is %d”, ++result);

printf(“\nThe value of p/q is %d”, result++);

Printf(“\nThe value of p/q is %d”, result - -);

result=p*q;

printf(“\nThe value of p*q is %d”, ++result);

printf(“\nThe value of p/q is %d”, result++);

printf(“\nThe value of p/q is %d”, result- -);

result=p%q;

printf("\nThe value of p%q is %d", ++ result);

printf("\nThe value of p/q is %d", result++);

printf("\nThe value of p/q is %d", result- -);

result=p&q;

printf("\The value of p&q is %d", ++result);

printf("\nThe value of p/q is %d", result++);

printf("\nThe value of p/q is %d", result- -);

result=p&&q;

printf("\nThe value of p&&q is %d", ++result);

printf("\nThe value of p/q is %d", result++);

printf("\nThe value of p/q is %", result- -);

return 0:

}

Output

5. Write a C program to find the area of a rectangle. The length and width of the rectangle are inputs.

Ans. Program

#include<stdio.h>

int main()

{

int len = 6, bre=7, area=0;

area=len * bre;

printf(“Area of rectangle is %d”, area);

return 0;

}

Output

6. Change the programming example B.1 to accept the integers from the keyboard using scanf() function.

Ans. Program

#include<stdio.h>

int main ()

{

int len, bre, area=0;
printf("Enter length");
scanf("%d",&len);
printf("Enter breadth");
scanf("%d", &bre);
area=len * bre;
printf("Area of rectangle is %d", area);
return 0;
}

Output

7. Improve the programming example B.5 to check whether the student scores PASS or FALL in individual subjects [Hint: use if clause].

Ans. Program

#include<stdio.h>

int main()

{

int mark__ eng; /mark for English.

int mark__ asm; // mark for Assamese.

int mark__ sci; //mark for Science.

int mark __ Soc; //mark for Social Science.

int mark__. math; //mark for Mathematics.

int mark__ comp; //mark for Computer.

int mark__ total; //Total marks scored by a student.

float marks__ average; //Average marks of 6 subjects.

/Getting marks for different subjects from keyboard as entered by an user of the program/.

printf (“\n::: Welcome to SEBA Student Marking System :::\n”);

printf(“\n Please enter mark for English and press ENTER:”);

scanf(“%d”, Please enter mark for Assamese and press ENTER:”);

scanf(“%d”, & mark_asm);

printf(“\n Please enter mark for Science and press ENTER:”);

scanf(“%d”, & mark_ sci);

Printf(“\n Please enter mark for Social Science and press ENTER:”);

scanf(“%d”, & mark_soc);

printf(“\n Please enter mark for Mathematics and press ENTER: ”);

scanf(“%d”, & mark_math);

printf(“\n Please enter mark for Computer Science and press ENTER:”);

scanf(“%”, & mark_ comp);

if(mark-eng < 30)

printf (“Failed in English”);

else if (mark-asm < 30)

printf (“Failed in Assamese”);

else if (mark-sci < 30)

Printf (“Failed in Science”);

else if (mark-soc < 30)

printf (“Failed in Social Science”);

else if (mark-math < 30)

printf (“Failed in Mathematics”);

else if (mark-comp < 30)

printf (“Failed in Computer Science”);

returen 0;

}

8. Improve the programming example B.5 to check whether every mark entered from the keyboard is positive or not. If any mark is wrongly entered as negative, prompt the user to re-enter. [Hint: use if clause and them put scanf()].

Ans. Program

#include<stdio.h>

int main()

{

int mark_ eng; //mark for English

int mark_ asm;//mark for Assamese

int mark_ sci: //mark for Science

int mark_ soc; //mark for Social Science

int mark_ math; //mark for Mathematics

int mark_ comp; //mark for Computer

int mark_ total; //Total marks scored by a student

float marks_ average; //Average marks of 6 subjects

/Getting marks for different subjects from keyboard as entered by an user of the program/

printf (“\n::: Welcome to SEBA Student Marking System :::\n”);

printf(“\n Please enter mark for English and press ENTER:”);

scanf(“%d”, & mark_ eng);

if (mark-eng < 0)

{

printf (“please re-enter the mark”);

printf (“please re-enter the mark”);

scanf(“%d”, & mark_ eng);

}

printf(“\n Please enter mark for Assamese and press ENTER:”);

scanf(“%d”, & mark_ asm);

if (mark-asm < 0)

{

printf(“please re-enter the mark”);

scanf(“%d”, & mark_asm);

}

printf(“\n Please enter mark for Science and press ENTER:”);

scanf(“%d”,& mark_sci;

if (mark-sci < 0)

{

printf (“please re-enter the mark”);

scanf(“%d”, & mark_ sci);

}

printf(“\n Please enter mark for Social Science and press ENTER:”);

scanf(“%d”, & mark_ soc);

if (mark-soc < 0)

{

printf (“please re-enter the mark”);

scanf(“%d”, & mark_soc);

}

printf(“\n Please enter mark for Mathematics and press ENTER:”);

scanf(“%d”,& mark_ math);

if (mark-math < 0)

{

printf (“please re-enter the mark”);

scanf(“%d”, & mark_math);

}

printf(“\n please enter mark for Computer Science and press ENTER:”);

scanf(“%d”, & mark_comp);

if (mark-comp < 0)

{

printf (“please re-enter the mark”);

scanf(“%d”, & mark_ comp);

}

return 0;

}

9. Write a program in C for awarding student grade (as example B.5) using switch-case construct.

Ans. Program

#include<stdio.h>

{

int mark_ eng; //mark for English

int mark_ asm; //mark for Assamese

int mark_ sci; //mark for Science

int mark_soc; //mark for Social Science

int mark_ math; //mark for Mathematics

int mark_ comp; //mark for Computer

int mark_ total; //Total marks scored by a student

float marks_ average; //Average marks of 6 subjects

/Getting marks for different subjects from keyboard as entered by an user of the program/

printf (“\n::: Welcome to SEBA Student Marking System :::\n”);

printf(“\n Please enter mark for English and press ENTER:”);

scanf(“%d”, & mark_ eng);

printf(“\n Please enter mark for Assamese and press ENTER:”);

scanf(“%d”, & mark_ asm);

printf(“\n Please enter mark for Science and press ENTER:”);

scanf(“%d”, & mark_sci;

printf(“\n Please enter mark for Social Science and press ENTER:”);

scanf(“%d”, & mark_ soc);

printf(“\n Please enter mark for Mathematics and press ENTER:”);

scanf(“%d”, & mark_ math;

printf(“\n Please enter mark for Computer Science and press ENTER:”);

scanf(“%d”, & mark_ comp);

/Marks are taken from keyboard; now doing calculation .../

mark_ total = mark _ eng + mark _ asm + sci + mark_ soc + mark_ math + mark_ comp;

printf(“\n Total marks scored by the student is: %d”, mark_ total);

marks_ average = mark_ total /6;

printf(“\n Average marks scored by the student is:%f”, marks_average);

Switch (marks_average)

{

case 80 : printf (“Grade A”);
break;

case 70 : printf(“Grade B”);
break;

case 60 : printf(“Grade C”);
break;

case 40 : printif (“Grade D”);
break;

case 30 : printf (“Grade E”);
break;

}

return 0;

}

ADDITIONAL QUESTIONS AND ANSWERS

1. Define identifiers.

Ans. An identifier is nothing but a name assigned to an element in a program. For example, name of a variable, function, etc.

2. What is character set?

Ans. The C character set consists of upper and lowercase alphabets, digits, special characters and white spaces.

3. What is the difference between variable and constant?

Ans. In C language, both constant and variable is widely used while designing a program. The major difference is between variables, and constant is that variable can alter its assigned value at any point of the program. In contrast, the value of the constant remains unaltered during the entire program.

4. Enumerate the basic data types in C.

Ans. There are 5 basic data types in C :

(a) int – Stores an integer number.

(b) float – Stores a decimal number.

(c) double – Stores a decimal number with the highest precision.

(d) char – Stores a single character.

(e) void – Stores no value.

5. What do you mean by reserved keywords? How many reserved keywords are there in C?

Ans. Words that are restricted for general use while writing a program, i.e., for using as a name for a variable, function, structure, etc. are called reserved keywords. Reserved keywords, also called reserved names, have special meanings, i.e., they are already defined for something.

The C programming language has the following 32 reserved keywords.

6. What is a variable?

Ans. A variable is an identifier that is used to store some value within a program. The value stored in a variable can change during the execution of program. A variable must be declared first before it used in the program.

7. In the following scanf( ) statement what is the use of ‘&’ symbol. scanf (“%d”, &a);

Ans. ‘&’ symbol indicates the address of the variable in computer memory. scanf() function requires the address of the variable to read input in it.

8. Define binary operator.

Ans. The operator that requires two operands is called a binary operator.

9. Define unary operator.

Ans. The operator that requires only one operand is called a unary operator.

10. What is assignment operator?

Ans. Assignment operator is used to assign a value to a variable.

11. Why relational operators are used?

Ans. Relational operators are used to compare values of two expressions and produce binary output (true or false) depending on the condition and the values of the operands. For example, if a=5 and b=7, then a > b will produce false.

12. What is conditional statement?

Ans. Conditional statements in C programming are used to make decisions based on the conditions. Conditional statements execute sequentially when there is no condition around the statements.

13. When do we use switch…case statement?

Ans. When we need to do a selection of statement execution in a program based on some integral value, we can use switch () construct of C. The value of the expression inside the switch () construct directs to different case and accordingly a block of statements are executed for one case.

14. What is the use of break statement in switch….case?

Ans. The break statement is used inside the switch to terminate a statement ent sequence. When a break statement is reached, the switch terminates, and the flow of control jumps to the next line following the switch statement.

15. Write the syntax of if… close statement.

Ans. If condition returns true then the statements inside the body of “if” are expected and the statements inside body of “else” are skipped.

If condition returns false then the statements inside the body of “if” are skipped and the statements in “else” are expected.

if(condition)

{

// Statements inside body of if 

}

else

{

// Statements inside body of else.

}

16. Write the syntax of switch… case statement.

Ans. The switch statement allows us to execute one code block among many alternatives.

You can do the same thing with the if…else..if ladder. However, the syntax of the switch statement is much easier to read and write.

Syntax of switch ….Case 

switch (expression)

{

case constant1: 

// statements

break;

case constant2:

// statements

break;

.

.

.

default: 

// default statements

}

17. What is the difference between if..else and switch…case statement?

Ans. The difference between if..else and switch…case statement are:

If…elseSwitch…case
An if-else statement can evaluate almost all the types of data such as integer, floating-point, character, pointer, or boolean.A switch statement can evaluate either an integer or a character.
In the case of ‘if-else’ statement, either the ‘if’ block or the ‘else’ block will be executed based on the condition.In the case of the ‘switch’ statement, one case after another will  be executed until the break keyword is not found, or the default statement is executed.
If the condition is not true within the ‘if’ statement, then by default, the else block statements will be executed.If the expression specified within the switch statement is not matched with any of the cases, then the default statement, if defined, will be executed.

Leave a Reply

error: Content is protected !!
Scroll to Top
adplus-dvertising