Pps Question

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

Previous year questions

Question 1: An employee can apply for loan at the begginning of every six months but he will be
sanctioned the amount as per rules:

Rule 1: an employee cannot enjoy more than two loans at any point of time

Rule 2: maximum permissible total loan is limited and depends upon the category of the employee.

write a c program to process the loan applications of the employees and sanction the loan.

Answer: #include <stdio.h>

// Define loan application rules

#define MAX_LOANS 2

#define EXECUTIVE_LIMIT 50000

#define MANAGER_LIMIT 25000

#define STAFF_LIMIT 10000

int main() {

// Declare variables to hold user input

int employee_id, category, loan_amount;

// Prompt the user to enter their employee ID, category, and desired loan amount

printf("Enter your employee ID: ");

scanf("%d", &employee_id);

printf("Enter your category (1 = Executive, 2 = Manager, 3 = Staff): ");

scanf("%d", &category);

printf("Enter the loan amount you would like to apply for: ");
scanf("%d", &loan_amount);

// Check if the user is eligible for a loan

if (loan_amount <= 0) {

printf("Invalid loan amount. Please try again.\n");

return 0;

if (category == 1 && loan_amount > EXECUTIVE_LIMIT) {

printf("Loan amount exceeds the maximum permissible amount for executives. Please try again.\
n");

return 0;

} else if (category == 2 && loan_amount > MANAGER_LIMIT) {

printf("Loan amount exceeds the maximum permissible amount for managers. Please try again.\n");

return 0;

} else if (category == 3 && loan_amount > STAFF_LIMIT) {

printf("Loan amount exceeds the maximum permissible amount for staff. Please try again.\n");

return 0;

// Check if the user has reached their maximum number of loans

int num_loans = 0; // Initialize to 0

// Add code here to read the employee's loan history from a database or file

if (num_loans >= MAX_LOANS) {

printf("You already have the maximum number of loans. Please pay off one of your existing loans
before applying for another.\n");
return 0;

// Calculate and display the loan amount that the user is eligible for

printf("Loan application approved for employee ID %d. You are eligible for a loan amount of Rs. ",
employee_id);

switch (category) {

case 1:

printf("%d\n", EXECUTIVE_LIMIT);

break;

case 2:

printf("%d\n", MANAGER_LIMIT);

break;

case 3:

printf("%d\n", STAFF_LIMIT);

break;

default:

printf("0\n");

// Add code here to update the loan database or file with the new loan information

return 0;

}
Question2: Using pointer write a function that receives the character string and a
character as an argument and deletes all occurences of that character in a string.
The function should return the corrected string with no holes.

Answer : #include <stdio.h>

void delete_char(char* str, char c) {

// Declare variables to hold pointer positions

char* src = str;

char* dest = str;

// Loop through the string and copy only the characters that are not equal to the given
character

while (*src != '\0') {

if (*src != c) {

*dest = *src;

dest++;

src++;

*dest = '\0'; // Add null terminator at the end of the new string

int main() {

char str[100], c;
printf("Enter a string: ");

fgets(str, 100, stdin);

printf("Enter a character to delete: ");

scanf("%c", &c);

delete_char(str, c);

printf("The corrected string with no holes is: %s", str);

return 0;

In the delete_char() function, two pointer variables are declared: src and dest. The
src pointer points to the beginning of the string, and the dest pointer points to the
beginning of the new string. In the while loop, the function checks each character of the
string. If the character is not equal to the given character c, it is copied to the new string
using the dest pointer. If the character is equal to c, it is skipped. After the loop, the
dest pointer points to the end of the new string, so a null terminator is added to mark
the end of the string.

In the main() function, the user is prompted to enter a string and a character to delete.
The delete_char() function is called with the string and character as arguments, and
the corrected string is printed. Note that the fgets() function is used to read the string
input because it is safer than using scanf() for input strings.

Question3 :write a program in c to calculate the bill amount for an item given its quantity
sold,value,discount and tax.

#include <stdio.h>
int main() {

int quantity;

float value, discount, tax, amount;

printf("Enter the quantity sold: ");

scanf("%d", &quantity);

printf("Enter the value per item: ");

scanf("%f", &value);

printf("Enter the discount percentage: ");

scanf("%f", &discount);

printf("Enter the tax percentage: ");

scanf("%f", &tax);

// Calculate the total amount before discount

amount = quantity * value;

// Apply discount

amount = amount - (amount * discount / 100);

// Apply tax

amount = amount + (amount * tax / 100);


printf("The bill amount is: %.2f\n", amount);

return 0;

In this program, the user is prompted to enter the quantity sold, value per item,
discount percentage, and tax percentage. These values are stored in variables quantity,
value, discount, and tax.

The program calculates the total amount before discount by multiplying the quantity
sold by the value per item. It then applies the discount by subtracting the discount
percentage from the total amount. Finally, it applies the tax by adding the tax
percentage to the discounted amount.

The resulting bill amount is stored in the amount variable and is printed to the console
using printf() with a precision of two decimal places using the format specifier %.2f.

Note that this program assumes that the discount and tax percentages are entered as
floating-point values between 0 and 100. If you want to calculate the discount and tax
amounts directly from the values entered by the user, you can divide them by 100
before applying them in the calculations.

Question 4:write a c program to check whether a given number is even or odd number or
not.

#include <stdio.h>

int main() {

int num;

printf("Enter a number: ");

scanf("%d", &num);

if (num % 2 == 0) {
printf("%d is an even number.\n", num);

} else {

printf("%d is an odd number.\n", num);

return 0;

Question 5: write a c program to calculate the compound interest.

#include <stdio.h>

#include <math.h>

int main() {

float principal, rate, time, interest, amount;

printf("Enter the principal amount: ");

scanf("%f", &principal);

printf("Enter the interest rate: ");

scanf("%f", &rate);

printf("Enter the time period (in years): ");

scanf("%f", &time);

// Calculate the compound interest

interest = principal * pow(1 + rate/100, time) - principal;


// Calculate the total amount

amount = principal + interest;

printf("Compound interest = %.2f\n", interest);

printf("Total amount = %.2f\n", amount);

return 0;

Question 6:write a c program that fills a 5*5 matrix as follows:

upper left triangle with +1s

lower right triangl with -1s

right to left diagnal with 0s.

#include <stdio.h>

int main() {

int matrix[5][5];

int i, j;

// fill the matrix

for (i = 0; i < 5; i++) {

for (j = 0; j < 5; j++) {

if (j <= i) {

matrix[i][j] = 1;

} else if (j > i + (4 - i) / 2) {
matrix[i][j] = -1;

} else {

matrix[i][j] = 0;

// print the matrix

for (i = 0; i < 5; i++) {

for (j = 0; j < 5; j++) {

printf("%d ", matrix[i][j]);

printf("\n");

return 0;

Question 7: Define a structure data type called time_struct containing three members
integer hour,integer minute and integer second.Develop a program in c that would assign
values to the individual members and display the time in the following format :

15 : 45 : 40

#include <stdio.h>

struct time_struct {

int hour;

int minute;
int second;

};

int main() {

struct time_struct time;

time.hour = 15;

time.minute = 45;

time.second = 40;

printf("%02d : %02d : %02d\n", time.hour, time.minute, time.second);

return 0;

Question 9:Define a structure data type named date containing three integer members
day,month and year.Develop an interactive modular program to perform the following
tasks

i)to read data into structure members by a function

ii)to validate tha data entered by another function.

iii)to print the data in format april 28, 2020 by a 3rd function.

#include <stdio.h>

struct date {

int day;

int month;

int year;

};
// function to read data into structure members

void read_date(struct date *d) {

printf("Enter the day: ");

scanf("%d", &d->day);

printf("Enter the month: ");

scanf("%d", &d->month);

printf("Enter the year: ");

scanf("%d", &d->year);

// function to validate the data entered

int validate_date(struct date d) {

int days_in_month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

if (d.month < 1 || d.month > 12) {

return 0;

if (d.day < 1 || d.day > days_in_month[d.month]) {

return 0;

if (d.month == 2 && d.day == 29 && (d.year % 4 != 0 || (d.year % 100 == 0 && d.year % 400 != 0))) {

return 0;

return 1;

}
// function to print the data in format "April 28, 2020"

void print_date(struct date d) {

char *months[] = {"", "January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December"};

printf("%s %d, %d\n", months[d.month], d.day, d.year);

int main() {

struct date d;

read_date(&d);

if (validate_date(d)) {

print_date(d);

} else {

printf("Invalid date.\n");

return 0;

Question 10: DEFINE THE TERM DEBUGGING EXPLAIN ANY TWO DEBUGGING TECHNIQUES.
Debugging is the process of finding and fixing errors (or bugs) in a computer program.
It is an essential part of software development and involves identifying and correcting
issues that prevent the program from functioning as intended.

The types of errors and the debugging techniques vary depending on the stage of development and the
environment.

Types of Possible Errors

To understand different types of debugging, we need to understand the different types of errors. Errors
are usually of three types:
Build and compile-time errors

Runtime errors

Logic errors

Build and compile-time errors happen at the development stage when the code is being built. These
errors are thrown by the compiler or the interpreter while building the source code. In other words,
build or compile-time errors prevent the application from even starting. These errors often result from
syntax errors, like missing semicolons at the end of a statement or class not found. These errors are easy
to spot and rectify because most IDE or compilers find them for you. The compiler or the interpreter will
tell you the exact piece of code that is causing the problem.

Runtime errors occur and can be identified only while running the application. They occur only when the
source code doesn’t have any compiler or syntax error, and the compiler or the interpreter cannot
identify the runtime error during the build stage. Mostly, runtime errors depend on the user input or the
environment. These kinds of errors can be identified by using try-catch blocks in your program and
logging the error message properly.

Logic errors occur after the program is successfully compiled and running and it gives you an output. A
logic error is when the result of the program is incorrect. These errors can not be caught using the try-
catch blocks. Logic errors are also called semantic errors, and they occur due to some incorrect logic
used by the developer to solve a problem while building the application.

Two common debugging techniques are:

1. Print debugging: This technique involves inserting print statements into the code to
display the values of variables or other information at specific points in the program's
execution. This can help identify where the program is going wrong and provide clues as
to what might be causing the issue.

For example, suppose a program is supposed to calculate the sum of two numbers, but
the result is incorrect. By adding print statements to display the values of the variables
used in the calculation, the programmer can see whether the values are what they
should be. If not, they can use the output to track down the problem.

2. Debugging tools: There are many software tools available to assist with debugging,
including integrated development environments (IDEs) that provide a debugger. A
debugger allows the programmer to step through the code one line at a time, examine
the values of variables at each step, and even modify the values to see how the program
reacts.
Debugging tools can also provide other helpful features, such as the ability to set
breakpoints, which pause the program's execution at a specific point, and watchpoints,
which trigger a pause when a specific variable is accessed or modified.

By using debugging techniques like these, programmers can quickly identify and fix
errors in their code, resulting in more reliable and functional software.

You might also like