23104B0007 PRABHUK sp3

You might also like

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

Q.

1 A manufacturing company has classified its executives into four levels for the
benefit of certain perks. The levels and corresponding perks are shown below: (10
Marks)

Level Perks Conveyance allowance Entertainment allowance

1 1000 500

2 750 200

3 500 100

4 250 0

An executive’s gross salary includes basic pay, house rent allowance at 25% of
basic pay and other perks. Income tax is withheld from the salary on a percentage
basis as follows:

Gross salary Tax deduction rate

Gross <= 2000 No tax deduction

2000 < Gross <= 4000 3%

4000 < Gross <= 5000 5%

Gross > 5000 8%

Write a C application that will read an executive’s level number and basic pay and
then compute the net salary after withholding income tax.

(Analysis: Gross salary = basic pay + house rent allowance + perks

ANSWER

#include <stdio.h>
void main()
{
int level;
float basicamt, Rent, perks, grossSalary, total, tax;
printf("Enter executive's level (1-4): ");
scanf("%d", &level);
printf("Enter basic pay: ");
scanf("%f", &basicamt);
switch (level) {
case 1:
Rent = 0.25 * basicamt;
perks = 1000 + 500;
break;
case 2:
Rent = 0.25 * basicamt;
perks = 750 + 200;
break;
case 3:
Rent = 0.25 * basicamt;
perks = 500 + 100;
break;
case 4:
Rent = 0.25 * basicamt;
perks = 250;
break;
default:
printf("Invalid level entered.\n");
return 1;
}
grossSalary = basicamt + Rent + perks;
if (grossSalary <= 2000)
tax = 0;
else if (grossSalary <= 4000)
tax = 0.03;
else if (grossSalary <= 5000)
tax = 0.05;
else
tax = 0.08;
total = grossSalary - (tax * grossSalary);
printf("Gross Salary: %.2f\n", grossSalary);
printf("Income Tax Deduction: %.2f\n", tax * grossSalary);
printf("Net Salary: %.2f\n", total);
}
Q.2 Identify one suitable problem statement where we need to make use of do-
while loop. Develop C application to solve that problem. Justify – Why it cannot be
solved by using for loop. (5 Marks)

Problem statement
a program that calculates the sum of a sequence of POSITIVE integers entered by
the user until the user enters a NEGATIVE number.
#include <stdio.h>
void main() {
int number, sum=0 ;
printf("Enter positive integers (enter a negative number to quit):\n");
do {
printf("Enter a number: ");
scanf("%d", &number);
if (number >= 0)
{
sum += number;
}
} while (number >= 0);
printf("Sum of the positive integers entered: %d\n", sum);
}
Justification for Using a do-while Loop:
This problem is perfect for a do-while loop because it needs the program to
repeatedly ask the user for input until a specific condition (entering a negative
number). The user may enter a variable number of positive integers, and we need
to calculate their sum. A do-while loop ensures that at least one positive integer is
processed before checking the exit condition, making it the right choice for this
task. Using a for loop is not appropriate for this problem because the number of
problems/numbers is not known in advance, and it doesn't fit the use case where
we keep accepting input until a certain condition is met.
Q.3 Are you interested in increasing your investment value? Given – Principal
amount (p), rate of interest (r) and duration in years (n) the investment value can
be calculated as

v = P(1 + r)n

Develop a C application which would give the value of v for different durations
starting from 1 to 10 years. (10 Marks)

(Analysis: Value of investment at the end of any year becomes the principal
amount for the next year)

#include <stdio.h>
#include <math.h>
void main() {
double p,r,v;
int years;
printf("Enter the principal amount (P): ");
scanf("%lf", &p);
printf("Enter the rate of interest (r) as a decimal: ");
scanf("%lf", &r);
if (r < 0 || r> 1) {
printf("Rate of interest should be in decimal form (0 to 1).\n");
return 1;
}
printf("Investment value for different durations:\n");
printf("Year\tValue (V)\n");
for (years = 1; years <= 10; years++) {
v = p * pow(1 + r, years);
printf("%d\t%.2lf\n", years, v);
}
}

You might also like