Name: Khan Zainab Rollno:24202A0025
Subject: Programming in C Subject Code: 312303
Semester: 2 Course: IF2K-A
Laboratory No: Name of Subject Teacher: Ms. Shonal Vaz
Applications:
Application 1:
Adding up the cost of each item in your shopping cart to get the final
amount you need to pay at the checkout.
Ans: Algorithm:
Step-by-Step Process:
1. Start the program.
2. Initialize the total cost to 0.
3. Input the price of Item 1, and add it to the total cost.
4. Input the price of Item 2, and add it to the total cost.
5. Input the price of Item 3, and add it to the total cost.
6. Display the total cost.
7. End the program.
Flowchart:
StartStart
Initialize the total cost to 0.
I nitialize totalCost = 0
Input thethe
Input price of of
price Item 1, and
Item add
1, and it to
add thethe
it to total
total
cost. cost.
Input the price of Item 2, and add it to the
Input thecost.
total price of Item 2, and add it to the total
cost.
Input
Input thethe price
price of of Item
Item 3, and
3, and addadd it to
in to the
the total
total
cost.
cost.
Display the Display
total cost.
the total cost.
End.
End
Output:
Application 2:
Show a simple table that shows the result of multiplying each number
from 1 to 5 by itself.
Ans: Algorithm:
Start
2. Set the range of numbers (1 to 5).
3. For each number in the range:
Multiply the number by itself.
Print the number and its result.
4. End
Flowchart:
St Start
Start
Set the range
Set the rangeofofnumbers
numbers(1 (1
to to
5).5).
ForFor
each
eachnumber
number(1
(1to
to 5)
5)
Multiply
Multiply number
number by itself
by itself
Display
Display result result
End
End
Output:
Application 3:
Set up a system to verify and calculate employees salaries.
The company has a policy that :If the employee salary is greater than or equal
to50,000, they are eligible for a bonus.
If the employee salary is between30,000 and49,999, they get a small bonus.
If the salary isbelow 30,000,the employee is not eligible for
any bonus.
Ans: Algorithm:
1) Start.
2) Input the employee's salary.
3) Check the salary range:
If the salary is greater than or equal to 50,000, assign a large bonus.
Else if the salary is between 30,000 and 49,999, assign a small bonus.
Else, if the salary is below 30,000, no bonus is assigned.
4) Output the salary and bonus amount.
5) End.
Flowchart:
Start
Input Salary
Is salary>50,000
Yes
No
Assign Large
Bonus.
Is salary between 30,000
and 49,999?
Yes
No
Assign Small Bonus Assign No Bonus
Display Salary and Bonus.
End
Program:
Output:
Application 4:
Setup a system to check the eligibility for admission to a university. A student is
eligible for admission if they meet the following conditions:
The student must score at least 60% in their high school exams.
The student must have passed the entrance exam.
Ans: Algorithm:
1. Start.
2. Input the high school score and the entrance exam result (pass/fail).
3. Check if the high school score is greater than or equal to 60%.
If No: Output “Not Eligible for Admission – Low High School Score” and stop.
If Yes: Proceed to step 4.
4. Check if the entrance exam result is "pass".
If No: Output “Not Eligible for Admission – Failed Entrance Exam” and stop.
If Yes: Proceed to step 5.
5. Output “Eligible for Admission”.
6. End.
Flowchart
Start
Input high school score and entrance exam
result
Is high school score>= 60%?
Not Eligible due to Low High
School Score."
Is the entrance
exam passed?
Not Eligible due to Failed
“Eligible for
Entrance Exam."
Admission”.
End
Program:
Output:
Application 5:
You have a number, and you need to change the value of a specific bit (like a tiny
switch) in that number. If the bit CO1is on (1), turn it off (0).If the bit is off (0), turn it on
(1).9 Implement minimum two C programs using simple If statement and if.. else
statement.
Ans: Algorithm:
1.Input the number and the position of the bit to be toggled.
1. Use a mask with the bitwise XOR (^) operator to toggle the specific bit:
If the bit is 0, XOR will turn it to 1.
If the bit is 1, XOR will turn it to 0.
2. Output the modified number after toggling the specific bit.
Flowchart:
Start
Input number (n) and position
of the bit to toggle (p)
Check if the p-th <--- If n & (1 << p) == 0
bits is 0?
No (Bit is 1) Yes (Bit is 0)
n = n & ~(1 << p) n = n (1 << p)
(Turn the bit off) (Turn the bit on)
Output the modified number
End
Program:
Output:
Application 6:
Out the total salary after adding a bonus based on how well the person
performed at work .Here’s how the bonus works:
If performance is" Excellent, " the bonus is 30% of the basic
salary.
If performance is"Good, " the bonus is 20% of the basic salary.
If performance is"Average, " the bonus is 10% of the basic
salary.
If performance is" Poor," no bonus is given.
Ans: Algorithm:
Input:
1. Enter the basic salary of the employee.
2. Enter the performance of the employee (Excellent, Good, Average, or Poor).
Decision Making:
3. If the performance is "Excellent", the bonus is 30% of the basic salary.
4. If the performance is "Good", the bonus is 20% of the basic salary.
a. If the performance is "Average", the bonus is 10% of the basic salary.
5. If the performance is "Poor", no bonus is given.
Output:
6. Calculate the total salary by adding the basic salary and the bonus.
7. Display the total salary.
Flowchart:
Start
Input basic salary and
performance
(Excellent/Good/ Average/Poor)
Is performance Excellent?
Yes No
Is performance
bonus = 30% of
Good?
basic salary
Is performance
Is performance poor?
Average?
No No Yes
Yes
bonus = 10% of bonus = 0 of bonus = 20% of
basic salary basic salary basic salary
Calculate total
Calculate total salary = basic salary
salary = basic salary + bonus
+ bonus
Output the salary
End
Program:
Output:
Application: 7
Simulate an ATM menu for basic operations.
Check Balance
Withdraw Cash
Deposit Funds
Transfer Funds
Change PIN
Exit
Ans: Program:
Output:
Application: 8
In online payments, sometimes the transaction might fail
because of internet problems. The system should prompt
the user to try again until the payment goes through or the
user decides to cancel.
Ans:
Output: