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.
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
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 Dev Library”);
}
2. List five commonly used operators of C programming language with their meanings.
Ans. Commonly used operators of C programming languages are listed below:
(1) Arithmetic Operators: These operators are used to perform arithmetic/mathematical operations on operands. Examples: (+, -, *, /, %,++,–).
(2) 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 (==, >=, <= ).
(3) Logical Operators: Logical operators are used when we want to combine two or more conditions or constraints. The logical operators always produce results in a boolean value, i.e., 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).
(4) Bitwise Operators: Bitwise operators are for bit-level operations on the operands. The operators first convert into bit-level and then perform the calculations.
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.
(5) 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. No, it is not true that the ‘scanf’ statement should always be preceded by a ‘printf’ statement in C.
In C, printf is used for output, which means it is used to display information on the screen or write it to a file. scanf, on the other hand, is used for input, which means it is used to read data from the user or from a file. These two functions serve different purposes and are used independently based on the needs of your program.
The printf () statement is written just to inform the user to enter 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; // This will result in a compilation error.
int Third Variable; // This will result in a compilation error.
int char; // This will result in a compilation error.
int number; // This is a valid variable name.
int -; // This will result in a compilation error.
int ---; // This will result in a compilation error.
int _x; // This is a valid variable name.
int 9months; // This will result in a compilation error.
int blp24; // This is a valid variable name.
int 8724; // This will result in a compilation error.
int dimatala; // This is a valid variable name.
int gogamukh??; // This will result in a compilation error.
int I want to be a doctor.; // This will result in a compilation error.
return 0;
}
The following variables are not allowed in C.
Name | Reason |
char | Key words are not allowed as variable. |
-, —-, gogamukh?? | A variable name can only have letters (both uppercase and lowercase letters), digits and underscore. |
_x, 9months, 8724 | Variable name must start with letter. |
I want to be a doctor | Spaces 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
The value of var is 7.
The address of var in memory is 0x7fff5fbff654.
Now, let’s relate this output to the concepts from Section 9.2:
‘The value of var is 7.’: This line shows the actual value stored in the var variable, which is 7. In memory, the space allocated for an int variable (var in this case) is used to store the value.
‘The address of var in memory is 0x7fff5fbff654.’: This line displays the memory address where the var variable is stored. It’s represented as a hexadecimal value. Each variable in C is stored at a specific memory address, and you can access that address using the & operator. Understanding the address of a variable is essential for memory management and pointer operations.
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
Size of the variable p is 4
Size of an integer is 4
Storage for the type of the variable p is 4
Now, let’s analyze the output and relate it to the concepts learned in Section 9.2 about the allocated space of a variable in computer memory:
The values of X, Y, and Z are all 4, which is common for a 32-bit system, where an ‘int’ typically uses 4 bytes of memory. This demonstrates how variables of a particular data type in C occupy memory space, and the ‘sizeof’ operator is used to determine the size of these variables or data types in bytes.
4. Write a C program to do the following.
(i) Declare three integer variables as int p = 9, q = 7, result = 0;
Ans. (i)
#include <stdio.h>
int main() {
int p = 9, q = 7, result = 0;
printf("Value of p: %d\n", p);
printf("Value of q: %d\n", q);
printf("Value of result: %d\n", result);
return 0;
}
Output
Value of p: 9
Value of q: 7
Value of 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);
Ans. (ii)
#include <stdio.h>
int main() {
int p = 9, q = 7, result;
// Perform the operations and store the results in the 'result' variable
result = p + q;
printf("p + q = %d\n", result);
result = p - q;
printf("p - q = %d\n", result);
result = p / q;
printf("p / q = %d\n", result);
result = p % q;
printf("p %% q = %d\n", result);
result = p + q;
printf("p + q (again) = %d\n", result);
result = p & q;
printf("p & q = %d\n", result);
result = p && q; // Note: It should be '&&' for logical AND
printf("p && q = %d\n", result);
return 0;
}
Output
p + q = 16
p - q = 2
p / q = 1
p % q = 2
p + q (again) = 16
p & q = 1
p && q = 1
(iii) Perform ++ result; result++; result – -; Display value of result at each step.
Ans. (iii)
#include <stdio.h>
int main() {
int result = 5;
printf("Initial value of result: %d\n", result);
// Perform ++result (increment before using the value)
++result;
printf("After ++result: %d\n", result);
// Perform result++ (use the current value, then increment)
result++;
printf("After result++: %d\n", result);
// Perform result-- (decrement)
result--;
printf("After result--: %d\n", result);
return 0;
}
Output
Initial value of result: 5
After ++result: 6
After result++: 7
After result--: 6
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() {
double length, width, area;
// Prompt the user for the length and width
printf("Enter the length of the rectangle: ");
scanf("%lf", &length);
printf("Enter the width of the rectangle: ");
scanf("%lf", &width);
// Calculate the area
area = length * width;
// Display the result
printf("The area of the rectangle is: %lf\n", area);
return 0;
}
Output
Enter the length of the rectangle: 8.5
Enter the width of the rectangle: 6.2
The area of the rectangle with length 8.50 and width 6.20 is 52.70
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\n", area);
return 0;
}
Output
Enter length: 8
Enter breadth: 5
Area of rectangle is 40
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_asm, mark_sci, mark_soc, mark_math, mark_comp;
printf("::: Welcome to SEBA Student Marking System :::\n");
printf("Please enter mark for English and press ENTER: ");
scanf("%d", &mark_eng);
printf("Please enter mark for Assamese and press ENTER: ");
scanf("%d", &mark_asm);
printf("Please enter mark for Science and press ENTER: ");
scanf("%d", &mark_sci);
printf("Please enter mark for Social Science and press ENTER: ");
scanf("%d", &mark_soc);
printf("Please enter mark for Mathematics and press ENTER: ");
scanf("%d", &mark_math);
printf("Please enter mark for Computer Science and press ENTER: ");
scanf("%d", &mark_comp);
if (mark_eng < 30)
printf("Failed in English\n");
if (mark_asm < 30)
printf("Failed in Assamese\n");
if (mark_sci < 30)
printf("Failed in Science\n");
if (mark_soc < 30)
printf("Failed in Social Science\n");
if (mark_math < 30)
printf("Failed in Mathematics\n");
if (mark_comp < 30)
printf("Failed in Computer Science\n");
return 0;
}
Output
::: Welcome to SEBA Student Marking System :::
Please enter mark for English and press ENTER: 75
Please enter mark for Assamese and press ENTER: 65
Please enter mark for Science and press ENTER: 45
Please enter mark for Social Science and press ENTER: 55
Please enter mark for Mathematics and press ENTER: 25
Please enter mark for Computer Science and press ENTER: 60
Failed in Mathematics
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_asm, mark_sci, mark_soc, mark_math, mark_comp;
printf("::: Welcome to SEBA Student Marking System :::\n");
do {
printf("Please enter mark for English and press ENTER: ");
scanf("%d", &mark_eng);
} while (mark_eng < 0);
do {
printf("Please enter mark for Assamese and press ENTER: ");
scanf("%d", &mark_asm);
} while (mark_asm < 0);
do {
printf("Please enter mark for Science and press ENTER: ");
scanf("%d", &mark_sci);
} while (mark_sci < 0);
do {
printf("Please enter mark for Social Science and press ENTER: ");
scanf("%d", &mark_soc);
} while (mark_soc < 0);
do {
printf("Please enter mark for Mathematics and press ENTER: ");
scanf("%d", &mark_math);
} while (mark_math < 0);
do {
printf("Please enter mark for Computer Science and press ENTER: ");
scanf("%d", &mark_comp);
} while (mark_comp < 0);
if (mark_eng < 30)
printf("Failed in English\n");
if (mark_asm < 30)
printf("Failed in Assamese\n");
if (mark_sci < 30)
printf("Failed in Science\n");
if (mark_soc < 30)
printf("Failed in Social Science\n");
if (mark_math < 30)
printf("Failed in Mathematics\n");
if (mark_comp < 30)
printf("Failed in Computer Science\n");
return 0;
}
Output
::: Welcome to SEBA Student Marking System :::
Please enter mark for English and press ENTER: 75
Please enter mark for Assamese and press ENTER: 65
Please enter mark for Science and press ENTER: -5
Please enter a positive mark for Science: 45
Please enter mark for Social Science and press ENTER: 55
Please enter mark for Mathematics and press ENTER: 25
Please enter mark for Computer Science and press ENTER: 60
Failed in Mathematics
9. Write a program in C for awarding student grade (as example B.5) using switch-case construct.
Ans. Program
#include <stdio.h>
int main() {
int mark_eng, mark_asm, mark_sci, mark_soc, mark_math, mark_comp, mark_total;
float marks_average;
// Getting marks for different subjects from the keyboard as entered by a user
printf("::: Welcome to SEBA Student Marking System :::\n");
printf("Please enter mark for English and press ENTER: ");
scanf("%d", &mark_eng);
printf("Please enter mark for Assamese and press ENTER: ");
scanf("%d", &mark_asm);
printf("Please enter mark for Science and press ENTER: ");
scanf("%d", &mark_sci);
printf("Please enter mark for Social Science and press ENTER: ");
scanf("%d", &mark_soc);
printf("Please enter mark for Mathematics and press ENTER: ");
scanf("%d", &mark_math);
printf("Please enter mark for Computer Science and press ENTER: ");
scanf("%d", &mark_comp);
// Calculate total marks and average marks
mark_total = mark_eng + mark_asm + mark_sci + mark_soc + mark_math + mark_comp;
marks_average = (float)mark_total / 6;
printf("Total marks scored by the student is: %d\n", mark_total);
printf("Average marks scored by the student is: %.2f\n", marks_average);
// Determine the grade using a switch-case statement based on average marks
switch ((int)marks_average / 10) {
case 10:
case 9:
printf("Grade A\n");
break;
case 8:
printf("Grade B\n");
break;
case 7:
printf("Grade C\n");
break;
case 6:
printf("Grade D\n");
break;
default:
printf("Grade F\n"); // Failed for marks less than 60
break;
}
return 0;
}
Output
::: Welcome to SEBA Student Marking System :::
Please enter mark for English and press ENTER: 75
Please enter mark for Assamese and press ENTER: 65
Please enter mark for Science and press ENTER: 85
Please enter mark for Social Science and press ENTER: 70
Please enter mark for Mathematics and press ENTER: 60
Please enter mark for Computer Science and press ENTER: 90
Total marks scored by the student is: 445
Average marks scored by the student is: 74.17
Grade B
Hi, I’m Dev Kirtonia, Founder & CEO of Dev Library. A website that provides all SCERT, NCERT 3 to 12, and BA, B.com, B.Sc, and Computer Science with Post Graduate Notes & Suggestions, Novel, eBooks, Biography, Quotes, Study Materials, and more.
It is a very good website
❤️