14 Group
14 Group
FACULTY:-VS NARAYANA.M
SUBJECT:-PROGRAMMING FOR PROBLEM SOLVING
BRANCH:-CSIT
BY:
• K Sai Sahasra:-23RH1A3340
• L Tejasri:-23RH1A3341
• M.Sreeja:-23RH1A3342
PRESENTATION ON
NESTED IF….
CONTENTS
WHAT IS IF STATEMENT
NESTED IF
ALGORITHM AND FLOWCHART
PROBLEM STATEMENT
SOURCE PROGRAM
OUTPUT
WHAT IS IF STATEMENT:
"if statement" is a control structure that allows you to make decisions in your code based on a condition. It is used to control
the flow of a program by executing certain code only if a specified condition is true.
You can also extend the if statement with an optional else block to specify what should happen if the condition is false.
Eg: if (condition) { =>Condition is an expression that evaluates to either true
// Code to be executed if the condition is true (non-zero) or false (zero).
=>If the condition is true, the code block enclosed in curly
} else { braces {} following the if statement will be executed.
// Code to be executed if the condition is false =>If the condition is false, the code block of if statement will
be skipped, and the program will execute code block of else
}
statements.
An organization incrementing salary based on number of service years and the basic payIf no of service years < 5,
basic pay is <12000 salary is increased by 6%, if basic pay is >12000 salary is increased by 8%.If no of service
years >5, basic pay is <12000 salary is increased by 8%, if basic pay is >12000 salary is increased by 10% .
PROGRAM:
#include <stdio.h>
int main() {
int serviceYears;
float basicPay, salary;
Step 1:
include the necessary header file:
#include <stdio.h>
This line includes the standard input/output library, which provides functions like printf and scanf for reading and displaying data .
Step 2:
Declare variables to store service years, basic pay, and salary:
int serviceYears;
float basicPay, salary;
Here, we declare three variables to store the number of service years, basic pay, and the calculated salary.
Step 3:
Prompt the user to enter the number of service years and basic pay:
printf("Enter the number of service years: ");
scanf("%d", &serviceYears);
Step 4:
Calculate the salary increment based on the conditions you specified:
if (serviceYears < 5) {
if (basicPay < 12000) {
salary = basicPay * 1.06;
} else {
salary = basicPay * 1.08;
}
} else {
if (basicPay < 12000) {
salary = basicPay * 1.08;
CODE EXPLANATION:
} else {
salary = basicPay * 1.10;
}
}
=>The code uses nested if-else statements to determine the salary increment. It first checks the number of service
years.
=>If it's less than 5, it checks the basic pay and increases the salary by 6% if the basic pay is less than 12000, or by
8% if the basic pay is greater than or equal to 12000.
=>If the number of service years is 5 or more, it applies different percentages (8% and 10%) based on the basic pay .
CODE EXPLANATION:
Step 5:
Display the calculated salary:
printf("The updated salary is: %.2f\n", salary);
Finally, the code uses printf to display the updated salary with two decimal places.
Output:
=> Enter the number of service years: 3
Enter the basic pay: 11000
The updated salary is: 11660.00
=> Enter the number of service years: 7
Enter the basic pay: 14000
The updated salary is: 15400.00
THANK
YOU