PSUC
PSUC
MCQ
Answer all the questions.
(1)
1. a+b=12.000
n-m=1.4
2. a+b=12.000
n-m=1.400
3. a+b=12
n-m=1.400
4. a+b=12 n-m=1.400
1. 0
2. 1
3. 2
4. -2
1. Equal
2. x<y
3. x>y
4. x not equal to y
Page 2 of 9
DESCRIPTIVE
Answer all the questions.
Q6. Differentiate among machine level, assembly level and high level languages. (3)
Solution:
Machine-level, assembly-level, and high-level languages differ primarily in abstraction, ease of use,
and proximity to the hardware:
1. Machine-Level Language (Machine Code)
• Definition: This is the lowest level of programming language, directly understood by the
computer's hardware (CPU).
• Nature: Binary (0s and 1s), which the machine's processor can execute directly.
• Example: 01001011 01101000 11100001 (Specific binary codes for operations).
• Pros:
o Executes extremely fast.
o Direct control over hardware.
• Cons:
o Extremely difficult to write, debug, and maintain.
o Not portable—machine code is specific to a given CPU architecture.
2. Assembly-Level Language (Assembly Code)
• Definition: A low-level language that uses symbolic representations of machine instructions.
• Nature: Uses mnemonics (shortcodes) and requires an assembler to convert the code to
machine language.
• Example: MOV AX, 01h (Move the hexadecimal value 1 into the AX register).
• Pros:
o More readable than machine code.
o Still allows for fine-grained control over hardware.
• Cons:
o Harder to learn and use than high-level languages.
o Not portable—assembly code is specific to a particular CPU architecture.
3. High-Level Language
• Definition: A programming language that is more abstracted from the hardware and designed
to be easy for humans to understand and use.
• Nature: Uses English-like syntax and concepts, and is translated to machine code by a
compiler or interpreter.
• Example: printf("Hello, World!") (C language).
• Pros:
o Easier to learn, write, and debug.
o Portable across different systems (compilers or interpreters handle architecture
differences).
• Cons:
o Less control over hardware.
o May be slower compared to assembly and machine code due to higher abstraction
levels.
Scheme : Machine level language: 1M, Assembly level language: 1M & High level languages: 1M
Page 3 of 9
Q7.Write an algorithm and flowchart to find whether the number is even or odd. (3)
Start
Algorithm:
Input n
Step 1: Start
Step 2: Input a number ‘n’ N
n%2==0
Y
Flowchart
Q8. What is a ternary operator in C? With proper syntax, explain the ternary (conditional) operator.
Write a complete C program to check whether the given year is a leap year using the ternary
operator. (4)
Solution:
As the name indicates, an operator that operates on three operands is called a ternary operator. C
has a conditional or ternary operator pair (? :) that uses a boolean condition to determine which of
two expressions is evaluated. [1 Mark]
Syntax:
condition ? expression1 : expression2
condition can be true or false.
If the condition is true, expression1 is evaluated; if it is false, expression2 is evaluated.
Example:
max=(a>b) ? a : b; // Compute maximum of a and b [1 Mark]
Program:
// C program to check leap year using conditional (ternary) operator.
#include <stdio.h>
int main() {
int year;
printf("Enter any year: ");
scanf("%d", &year);
(year%4==0 && year%100!=0) ? printf("LEAP YEAR") : (year%400 ==0 ) ? printf("LEAP YEAR") :
printf("COMMON YEAR");
return 0;
}
[Scheme: Input & output: 1 Mark, correct use of ternary operator: 1 Mark]
Q9.Write a C program to calculate income tax based on the tax slabs for individuals. The program
should prompt the user to input their annual income and display the total tax payable according to
the following tax slabs. The income tax calculation is as follows:
Page 4 of 9
1. For income up to Rs. 2,50,000: No tax
2. For income Rs. 2,50,001 to Rs. 5,00,000: 5% on the income exceeding Rs. 2,50,000
3. For income Rs. 5,00,001 to Rs. 10,00,000: 20% on the income exceeding Rs. 5,00,000
4. For income above Rs. 10,00,000: 30% on the income exceeding Rs. 10,00,000
Also, include an additional 4% health and education cess on the calculated tax.
Expected sample output:
Enter your annual income: Rs. 7,50,000
Income Tax: Rs. 62,500
Health and Education Cess: Rs. 2,500
Total Tax Payable: Rs. 65,000 (3)
Solution:
#include <stdio.h>
int main() {
float income, tax = 0.0, cess = 0.0, totalTax;
return 0;
}
[Scheme: input: 0.5M, output: 0.5M, Income tax calculation: 2M]
Page 5 of 9
Q10. (A) It is required to write a C program to guess a secret number that is defined as an integer
constant within the C program. (Let the secret number be 5).
Conditions to be satisfied by the program:
• Let the secret number take values between 1 and 10.
• The program should use a loop to continuously allow the user to enter a guess number.
• If the guess number is greater than the secret number, it should display 'Greater than secret
number'.
• If the guess number is lesser than the secret number, it should display 'Lesser than secret
number'.
• If the guess number is equal to the secret number, it should display 'Congratulations, You
have guessed it right'
• The program should exit only when the user enters a value of -1.
Suggest which loop construct of C would you select to solve the above problem? Justify your
selection.( DO NOT write the program or algorithm or flowchart)
(B) With the help of a suitable example, explain the exit-controlled loop. (3)
[Solution & Scheme:
(A) Loop to be selected: Do-While loop [0.5M]; Justification: The body of loop should be executed
atleat once [0.5M]
(B) Explanation of exit-controlled loop (Do-While Loop): (Syntax and flow chart expected): [1M]
Example C program on Do-While Loop: [1M]
#include <stdio.h>
int main()
{
int n, arr[20], even[10], odd[10],i, neven=0, nodd=0;
Page 6 of 9
//Displaying elements of main array
for(i=0; i<n; i++)
printf("arr[%d] = %d\t",i,arr[i]);
printf("\n");
return 0;
}
[Scheme: Reading array: 1M, Separating even and odd nos. in separate arrays: 2M, Display
elements of even nos. array: 0.5 M, Display elements of odd nos. array: 0.5 M.]
Q12. Illustrate the binary search technique to search 80 in a given 1D array 10, 12, 20, 32, 50, 55,
65, 80, 99. Show clearly all the required intermediate steps. (Note: Do not write algorithm or
program). (2)
Solution:
Illustration:
Page 7 of 9
[Scheme: Overall Illustration: ½ Marks; each correct step carries: ½ Marks]
Q13. Imagine you are developing a system for a car service station that needs to manage the car
records. Each car record has a unique ID number. Due to an emergency, the system must quickly
sort these records by the car ID to prioritize the cars with the lowest IDs first. Write a C program
that sorts an array of car IDs using Selection Sort algorithm. (3)
Page 8 of 9
Solution:
#include <stdio.h>
int main()
{
int CarIDs[100], n, i, j, minIndex, temp, newID, pos;
return 0;
}
[Marking Scheme: input: 1M; Selection Sort: 1M and output: 1M]
#####
Page 9 of 9