Set2 With Solutions
Set2 With Solutions
Instructions : 1. Scientific calculators are permitted. Sharing of calculator is not allowed.
2. Use clear and precise language while articulating the answers.
3. Partial answers or just the final answer will not be evaluated.
4. Answer all parts of the question in one place. Answers anywhere else will not be considered
for grading.
PART-A (5 x 2 = 10 Marks)
Answer any 5 from the
following questions
Answer:
Pseudocode:
1. Start
2. Input: binary_string = "1101"
3. Initialize integer_value = 0
4. For each bit in binary_string (starting from the left):
a. Multiply integer_value by 2
b. Add the current bit to integer_value
5. Output: integer_value
6. End
For the input "1101", the integer value will be 13.
2 . Write a pseudo code to accept a value in degrees Celsius and to convert it into 2 1
Fahrenheit. [Hint: C/5 = (F-32)/9].
Answer:
Pseudocode:
1. Start
2. Input: Celsius
3. Fahrenheit = (Celsius * 9/5) + 32
4. Output: Fahrenheit
5. End
This pseudocode follows the formula: (Celsius/5)=(Fahrenheit−32)/9(\text{Celsius}/5) =
(\text{Fahrenheit}-32)/9(Celsius/5)=(Fahrenheit−32)/9.
3 What will be the value of the variables at each line, from the following 2 1
code statements
1. int s, m=3, n=5, r, t;
2. float x=3.0, y; t = n/m;
3. r = n%m; y = n/m;
4. t = x*y-m/2; x = x*2.0;
Solution Rubric: 1/2 Marks for each part. So total 2 marks
Answer:
Values of variables in code statements:
1. int s, m = 3, n = 5, r, t;
m = 3, n = 5
3. r = n % m; y = n / m;
r = 2 (5 % 3 = 2), y = 1.6667 (floating-point division)
4. t = x * y - m / 2; x = x * 2.0;
t = 3.0 * 1.6667 - 3/2 = 5.0 - 1.5 = 3.5
x = 6.0
Answer:
The code prints "water" when the temperature T is between 32°F and 212°F (inclusive of 32 but less than 212).
5 Define what is a computer program and explain its role in our life. 2 1
Answer:
● A computer program is a sequence of instructions written to perform a specific task by a computer. It is
written in a programming language and defines the steps needed for the computer to follow to solve a
problem.
● Role in our life: Programs are essential in all modern technologies, including communication,
transportation, healthcare, entertainment, and education. They control everything from mobile apps to
complex systems like financial markets.
Solution Rubric:2 Marks for the correct answer. Partially correct give 1mark.
Answer:
Correcting the errors in the given C program:
#include <stdio.h>
void main() {
int breadth;
float length, height;
scanf("%d %f %f", &breadth, &length, &height); // Corrected scanf syntax
printf("%d %f %e", breadth, length, height); // Corrected printf syntax
}
Errors corrected: fixed formatting in scanf and printf statements and added & symbols correctly.
7 How does the following expression work in C language with respective ++i? 2 1
i = i++;
Answer:
● The expression i = i++ causes undefined behavior in C, meaning the result can be unpredictable
depending on the compiler. The value of i is incremented after its current value is used, but assigning i to
itself in this way can lead to ambiguity.
● ++i increments the value before using it, making it more predictable.
PART B (3 x 5 = 15 Marks)
Answer ANY three of the
following questions
S. No Descriptive Marks CLOs
Questions
8. . Draw the block diagram of a computer and explain each component briefly. 5 1,2
Solution Rubric:
5 Marks for the correct answer. Diagram 1 marks and remaining 4 marks.
Sample Answer:
The Central Processing Unit (CPU) is also known as "the brain of computer". It controls operation of all
components of a computer. A CPU itself has three components which are as follows −
A memory is a hardware component which is used to store and access the data whenever required.
Majorly, computer memory is categorised into two parts Primary Memory (RAM) and Secondary
Memory (Hard Disk). RAM is used for short-term, fast data access and is essential for active program
execution. On the other hand, storage or secondary memory provides permanent data storage. Hence,
memory and storage units both are critical components of a computer system
I/O devices, or input/output devices, are hardware components that allow a computer to communicate
with the outside world by sending and receiving data. I/O devices are a key concept in computing and are
essential for interacting with a computer:
● Input devices: Allow users to input data into the computer, such as keyboards and mice.
● Output devices: Allow users to receive data from the computer, such as monitors and
printers.
● Dual-purpose devices: Allow users to both input and output data, such as webcams
A computer's control unit (CU) is a key component of the central processing unit (CPU) that manages the
processor's operation as
● Directs instruction execution
● Controls data flow
● Manages resources
● Handles input and output
● Regulates timing
● Sends and receives control signals
9 a) Define flowchart? What are symbols which are used for the construct of a 5 1,2
flowchart?
Solution Rubric: Part a carries 1 mark. Part b carries 4 marks. If part b partially correct carries 2 marks.
Sample Answer:
a.
Flowchart is a diagrammatic representation of sequence of logical steps of a program. Flowcharts use simple
geometric shapes to depict processes and arrows to show relationships and process/data flow.
b.
10 a) What are the bitwise operators in C? 5 1
b) Write a program in C covering all bitwise operators?
Solution Rubric: Part a carries 2 mark. Part b carries 3 marks. If part a and part b partially correct carries 1 mark for
each part.
Sample Answer:
a. During computation, mathematical operations like: addition, subtraction, multiplication,
division, etc are converted to bit-level which makes processing faster and saves power.
Bitwise operators are used in C programming to perform bit-level operations.
| Bitwise OR
^ Bitwise exclusive OR
~ Bitwise complement
Solution Rubric: Part a carries 2 mark. Part b carries 3 marks. If part a and part b partially correct carries 1
mark for each part.
Sample Answer:
a. Operator Precedence
Operator precedence helps us determine which of the operators in an expression must be evaluated first in case the
expression consists of more than a single operator.
Example,
50 – 2 * 15 is going to yield 20. It is because it gets evaluated as 50 – (2 * 15), and not as (50 – 2) * 15. The reason
here is that subtraction (-) has lower precedence as compared to multiplication (*).
Operator Associativity
We use associativity when two or more than two operators with the same precedence are present in the same
expression.
Example,
The precedence of Division and Multiplication arithmetic operators is the same. So, let’s say we have an expression
with us which is 6 * 3 / 20. The evaluation of this expression would be (6 * 3) / 20 because the associativity will be
left to right for both the operators – multiplication and division. In a similar case, the calculation of 40 / 4 * 5 would
be (40 / 4) * 5 because the associativity would be from right to left here as well.
b. C provides the facility, where the data type of one operand is converted into the data type of another operand. This
is known as type conversion.
Implicit type conversion (Automatic): The type conversion is the process of converting a data value
from one data type to another data type automatically by the compiler. The implicit type conversion
is automatically performed by the compiler.
Explicit type conversion (Type casting): Explicit type conversion rules out the use of a compiler for
converting one data type to another instead the user explicitly defines within the program the data
type of the operands in the expression
Syntax:
(datatype) expression
Example:
Implicit:
#include<stdio.h>
#include<conio.h>
void main(){
int i = 95 ;
float x = 90.99 ;
char ch = 'A' ;
i=x;
printf("i value is %d\n",i);
x=i;
printf("x value is %f\n",x);
i = ch ;
printf("i value is %d\n",i);
}
Explicit:
#include<stdio.h>
int main()
{
double x = 1.2;
// Explicit conversion from double to int
int sum = (int)x + 1;
printf("sum = %d", sum);
return 0;
}
Solution Rubric: Part a carries 1 mark. Part b carries 4 marks. If part b partially correct carries 2 marks.
Sample Answer:
a. If-Else: In the programming world, if-else is a conditional statement that executes the
group of statements, based on whether the statement is true or false. In case the statement
is true, the if statement will execute it accordingly, and if the condition is not true, another
statement will start the process for execution.
Switch Case: The switch statement checks the value of a variable and compares it with
numerous possibilities. Once we find the match, the statement of that specific case is
executed.
b.
#include <stdio.h>
int main() {
char operation;
float n1, n2;
switch(operation)
{
case '+':
printf("%.1f + %.1f = %.1f",n1, n2, n1+n2);
break;
case '-':
printf("%.1f - %.1f = %.1f",n1, n2, n1-n2);
break;
case '*':
printf("%.1f * %.1f = %.1f",n1, n2, n1*n2);
break;
case '/':
printf("%.1f / %.1f = %.1f",n1, n2, n1/n2);
break;
return 0;
}
Output:
Enter an operator (+, -, *, /): *
Enter two operands: 3
4
3.0 * 4.0 = 12.0