0% found this document useful (0 votes)
7 views11 pages

Set2 With Solutions

The document outlines an examination format for a B. Tech CSE course, including instructions and a breakdown of questions divided into two parts: Part A with short questions and Part B with descriptive questions. Each question has specified marks and learning outcomes, covering topics such as pseudocode, C programming, computer components, flowcharts, bitwise operators, operator precedence, and type conversion. The document also provides sample answers and rubrics for grading.

Uploaded by

pavanesh370
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)
7 views11 pages

Set2 With Solutions

The document outlines an examination format for a B. Tech CSE course, including instructions and a breakdown of questions divided into two parts: Part A with short questions and Part B with descriptive questions. Each question has specified marks and learning outcomes, covering topics such as pseudocode, C programming, computer components, flowcharts, bitwise operators, operator precedence, and type conversion. The document also provides sample answers and rubrics for grading.

Uploaded by

pavanesh370
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/ 11

Batch​ : 2024-28 Max Marks : 25 marks

Degree & Branch : B. Tech & CSE Duration : 60 min.


Subject Code​ : Fundamentals of Subject Code : CSE 101
Computing and
Programming in C

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

S. No Short Questions Marks CLOs


1 Write a pseudocode for the following problem:
Given a binary representation 1101, prints the equivalent representation integer 2 1
format.

Solution Rubric: 2 Marks for the correct answer.

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

Solution Rubric: 2 Marks for the correct answer.

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

2.​ float x = 3.0, y; t = n/m;


t = 1 (integer division, 5 / 3 = 1)

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

4 Under what conditions does the following code print ``water''? 2 1


​ if(T < 32)
​ ​ printf("ice\n");
​ else if(T < 212)
​ ​ printf("water\n");
​ else​ printf("steam\n");

Solution Rubric: 2 Marks for the correct answer.

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

Solution Rubric:2 Marks for the correct answer.

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.

6 Correct the errors in the following C program 2 1


#include< stdio .h>
void main() {
int breadth; float length, height;
scanf(“%d%f%6.2f”,breadth,&length,height);
printf(“%d %f %e”,&breadth, length, height);
}

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++;

Solution Rubric:2 Marks for the correct answer.

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 −

●​ Control Unit (CU)

●​ ALU(Arithmetic Logic Unit)

●​ Memory or Storage Unit

Arithmetic Logic Unit (ALU):


The Arithmetic Logic Unit (ALU) is a component that has been extensively optimised and engineered to
do multiple tasks concurrently. It is commonly built to execute operations speedily. It works in
conjunction with other CPU components, such as registers, memory, and control units, to execute
complex instructions

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?

b) Draw the flowchart to find the roots of a quadratic equation?

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.

Symbol Symbol Name Purpose


Used at the beginning and end of
Start/Stop the algorithm to show start and
end of the program.

Indicates processes like


Process
mathematical operations.

Used for denoting program inputs


Input/ Output
and outputs.

Stands for decision statements in


Decision a program, where answer is
usually Yes or No.

Shows relationships between


Arrow
different shapes.

Connects two or more parts of a


On-page Connector flowchart, which are on the same
page.

Connects two parts of a flowchart


Off-page Connector which are spread over different
pages.

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.

Operators Meaning of operators


& Bitwise AND

| Bitwise OR

^ Bitwise exclusive OR

~ Bitwise complement

<< Shift left

>> Shift right

b.​ Example program:


#include <stdio.h>
int main() {
int a = 12, b = 25;
printf("Output = %d\n", a & b);
printf("Output = %d\n", a | b);
printf("Output = %d\n", a ^ b);
printf("Output = %d\n", ~35);
printf("Output = %d\n", ~-12);
printf("b<<1 = %d\n", b << 1);
printf("b>>1 = %u\n", b >> 1);
return 0;
}
Output:
Output = 8
Output = 29
Output = 21
Output = -36
Output = 11
b<<1 = 50
b>>1 = 12

11 a) What is operator precedence and operator associativity? 5 1


b) What is type conversion and explain its types?

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;
}

12 a) Differentiate between if else and switch? 5 1,2


b) Write a C program to create a simple calculator using switch?

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;

printf("Enter an operator (+, -, *, /): ");


scanf("%c", &operation);
printf("Enter two operands: ");
scanf("%f %f",&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;

// operator doesn't match any case constant +, -, *, /


default:
printf("Error! operator is not correct");
}

return 0;
}

Output:
Enter an operator (+, -, *, /): *
Enter two operands: 3
4
3.0 * 4.0 = 12.0

You might also like