JNTUH Model Paper Answers With Explanations
JNTUH Model Paper Answers With Explanations
Alogrithm Def:
Steps:
See notes
Explanation: This algorithm uses the quadratic formula to find the roots based
on the discriminant, which helps determine whether the roots are real or
complex.
4. Provide pseudocode to find the minimum and maximum numbers in a given set
of integers. (5M)
Definition
The algorithm to find the minimum and maximum numbers in a given set of
integers involves iterating through the list of integers to compare each number. The
minimum and maximum values are updated based on comparisons as the algorithm
processes each element.
Pseudocode: Find Min and Max
FUNCTION FindMinMax(numbers: ARRAY OF INTEGER):
IF numbers is EMPTY THEN
RETURN "Array is empty"
Example Usage
Logical Errors: These errors occur when the program runs without crashing but
produces incorrect results due to a mistake in the logic of the code. For example:
int main() {
int a = 10, b = 5;
printf("The sum is: %d", a - b); // Logical error: should be a + b
}
6. Describe the different storage classes in C, specifically auto, extern, static, and
register. (5M)
auto: This is the default storage class for local variables. These variables are
created when the block is entered and destroyed when it is exited. They are not
accessible outside their block.
extern: This storage class is used to declare a variable that is defined in another
file or function. It allows the use of the same variable across multiple files,
facilitating global access.
#include <stdio.h>
int main() {
int num, i, isPrime = 1; // Flag to check if the number is prime
printf("Enter a number: ");
scanf("%d", &num);
if (num <= 1) {
isPrime = 0; // Numbers less than 2 are not prime
} else {
for (i = 2; i <= num / 2; i++) { // Loop from 2 to num/2
if (num % i == 0) { // If num is divisible by i
isPrime = 0; // Not a prime number
break; // Exit loop
}
}
}
if (isPrime)
printf("%d is a prime number.\n", num);
else
return 0;
}
// Bitwise AND
int andResult = a & b; // 0101 & 0011 = 0001 (1 in decimal)
printf("Bitwise AND of %d and %d is: %d\n", a, b, andResult);
// Bitwise OR
int orResult = a | b; // 0101 | 0011 = 0111 (7 in decimal)
printf("Bitwise OR of %d and %d is: %d\n", a, b, orResult);
// Bitwise XOR
int xorResult = a ^ b; // 0101 ^ 0011 = 0110 (6 in decimal)
printf("Bitwise XOR of %d and %d is: %d\n", a, b, xorResult);
// Bitwise NOT
int notResultA = ~a; // ~0101 = 1010 (in 2's complement, this is -6)
return 0;
}
Explanation of Bitwise Operations
1. Bitwise AND (&):
See notes definition, truth table and example
2. Bitwise OR (|):
See notes definition, truth table and example
3. Bitwise XOR (^):
See notes definition, truth table and example
4. Bitwise NOT (~):
See notes definition, truth table and example
Program Output
When you run the program, the output will be:
Bitwise AND of 5 and 3 is: 1
Bitwise OR of 5 and 3 is: 7
Bitwise XOR of 5 and 3 is: 6
Bitwise NOT of 5 is: -6
Bitwise NOT of 3 is: -4
1. Header Files:
#include <stdio.h>: Includes standard input-output functions.
#include <stdlib.h>: Includes functions like atoi() for string to integer
conversion.
2. Main Function:
int main(int argc, char *argv[]): The main function accepts command-
line arguments where argc is the count of arguments and argv is an array
of argument strings.
3. Check for Arguments:
The program checks if the number of arguments (argc) is less than 2 (the
first argument is the program name). If true, it prints a message and exits.
4. Calculate Sum:
TEJA KOTAMRAJU Page 8
A for loop iterates through each command-line argument starting from
index 1 (the first argument after the program name).
atoi(argv[i]) converts the string argument to an integer, and this value is
added to the sum.
5. Print Result:
Finally, the program prints the calculated sum of the integers.
10. Create a flowchart for a program that finds the maximum number in a set of
integers. Explain each step in the flowchart.
1. Improved Readability: The use of functions and control structures makes code
easier to read and understand.
2. Ease of Maintenance: Code changes can be made in specific functions without
affecting the entire program, simplifying debugging and updates.
3. Reusability: Functions can be reused in different programs, reducing
redundancy.
4. Enhanced Collaboration: Multiple programmers can work on different
functions simultaneously, improving team productivity.
5. Clearer Logic Flow: The structured approach helps in visualizing the program's
logic flow, making it easier to trace the execution path.
#include <stdio.h>
// Main function
int main() {
int number = getUserInput(); // Get user input
if (number < 0) {
printf("Factorial is not defined for negative numbers.\n");
} else {
int result = factorial(number); // Calculate factorial
displayResult(number, result); // Display the result
}
return 0; // Exit the program
}
12. Discuss operators and their precedence in C. Provide examples for different
types of operators and demonstrate expression evaluation.
Operators in C?(15m)
Operators in C are special symbols that perform operations on variables and values.
They can be classified into several categories based on their functionality. Here’s a
detailed discussion of different types of operators in C along with their precedence:
1. Arithmetic Operators
+ Addition a+b
- Subtraction a-b
* Multiplication a*b
/ Division a/b
% Modulus a%b
== Equal to a == b
!= Not equal to a != b
3. Logical Operators
` `
! Logical NOT !a
4. Bitwise Operators
` ` Bitwise OR
~ Bitwise NOT ~a
5. Assignment Operators
6. Unary Operators
- Unary minus -a
+ Unary plus +a
3 *, /, % Left to Right
4 +, - Left to Right
9 ^ Left to Right
10 ` `
12 `
#include <stdio.h>
int main() {
int result;
// Example expression
result = a + b * c - a / 5 + (c % b) * (a + b);
return 0;
Expression Breakdown
a/5→5/5=1
c % b → 15 % 10 = 5
(a + b) → 5 + 10 = 15
5 * 15 = 75
2. Addition and Subtraction:
a + 150 - 1 + 75
5 + 150 = 155
155 - 1 = 154
154 + 75 = 229
Result: 229