filmov
tv
Program Logic/Algorithm - Calculate the No. of Notes and Electricity Bill using If-Else | Part 7

Показать описание
Try to Understand the Logic and Implement in Any Programming Language ( c/c++/java/python/c#/etc): Branching Statement
if you like my video, please subscribe to my channel and share the video
Write a C/Java/C++/Python program to input amount from user and print minimum number of notes (Rs. 500, 100, 50, 20, 10, 5, 2, 1) required for the amount. How to the minimum number of notes required for the given amount in C/Java/C++/Python programming.
input amount =1075;
if(amount greater than equal 500 ) // 1075 greater than equal 500 true
{
note_500 = amount /500; // 2
money_500 = note_500 * 500; // 2 * 500 - 1000
amount = amount - money_500; // 1075 - 1000 = 75
}
if(amount greater than equal 100 ) // 75 greater than equal100 false
{
note_100 = amount /100;
money_100 = note_100 * 100;
amount = amount - money_100;
}
if(amount greater than equal 50 ) // 75 greater than equal 50 true
{
note_50 = amount /50; // 1
money_50 = note_50 * 50; // 1 * 50 = 50
amount = amount - money_50; // amount = 75 - 50 = 25
}
if(amount greater than equal 20 ) // 25 greater than equal 20 true
{
note_20 = amount /20; // 1
money_20 = note_20 * 20; // 1 * 20 = 20
amount = amount - money_20; // amount = 25 - 20 = 5
}
if(amount greater than equal 10 ) // 5 greater than equal 10 false
{
note_10 = amount /10;
money_10 = note_10 * 10;
amount = amount - money_10;
}
if(amount greater than equal 5 ) // 5 greater than equal 5 true
{
note_5 = amount /5; // 1
money_5 = note_5 * 5; // 5
amount = amount - money_5; // amount = 5 - 5 = 0
}
if(amount greater than equal 2 ) // 0 greater than equal 2 false
{
note_2 = amount /2;
money_2 = note_2 * 2;
amount = amount - money_2;
}
if(amount greater than equal 1 ) // 0 greater than equal1 false
{
note_1 = amount /1;
money_1 = note_1 * 1;
amount = amount - money_5;
}
Example
Input amount: 1075
Output
Total number of notes:
500: 2
100: 0
50: 1
20: 1
10: 0
5: 1
2: 0
1: 0
Practice Yourself :
Q1. Write a C/Java/C++/Python program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following:
Percentage greater than equal 90% : Grade A
Percentage greater than equal 80% : Grade B
Percentage greater than equal 70% : Grade C
Percentage greater than equal 60% : Grade D
Percentage greater than equal40% : Grade E
Percentage less than 40% : Grade F
Q2. Write a C/Java/C++/Python program to input basic salary of an employee and calculate its Gross salary according to following:
Basic Salary less than equal 10000 : HRA = 20%, DA = 80%
Basic Salary less than equal 20000 : HRA = 25%, DA = 90%
Basic Salary greater than 20000 : HRA = 30%, DA = 95%
Write a C/Java/C++/Python program to input electricity unit charges and calculate total electricity bill according to the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill
Instagram: techtalk_debu
Thanks & Regards,
Debu Paul
if you like my video, please subscribe to my channel and share the video
Write a C/Java/C++/Python program to input amount from user and print minimum number of notes (Rs. 500, 100, 50, 20, 10, 5, 2, 1) required for the amount. How to the minimum number of notes required for the given amount in C/Java/C++/Python programming.
input amount =1075;
if(amount greater than equal 500 ) // 1075 greater than equal 500 true
{
note_500 = amount /500; // 2
money_500 = note_500 * 500; // 2 * 500 - 1000
amount = amount - money_500; // 1075 - 1000 = 75
}
if(amount greater than equal 100 ) // 75 greater than equal100 false
{
note_100 = amount /100;
money_100 = note_100 * 100;
amount = amount - money_100;
}
if(amount greater than equal 50 ) // 75 greater than equal 50 true
{
note_50 = amount /50; // 1
money_50 = note_50 * 50; // 1 * 50 = 50
amount = amount - money_50; // amount = 75 - 50 = 25
}
if(amount greater than equal 20 ) // 25 greater than equal 20 true
{
note_20 = amount /20; // 1
money_20 = note_20 * 20; // 1 * 20 = 20
amount = amount - money_20; // amount = 25 - 20 = 5
}
if(amount greater than equal 10 ) // 5 greater than equal 10 false
{
note_10 = amount /10;
money_10 = note_10 * 10;
amount = amount - money_10;
}
if(amount greater than equal 5 ) // 5 greater than equal 5 true
{
note_5 = amount /5; // 1
money_5 = note_5 * 5; // 5
amount = amount - money_5; // amount = 5 - 5 = 0
}
if(amount greater than equal 2 ) // 0 greater than equal 2 false
{
note_2 = amount /2;
money_2 = note_2 * 2;
amount = amount - money_2;
}
if(amount greater than equal 1 ) // 0 greater than equal1 false
{
note_1 = amount /1;
money_1 = note_1 * 1;
amount = amount - money_5;
}
Example
Input amount: 1075
Output
Total number of notes:
500: 2
100: 0
50: 1
20: 1
10: 0
5: 1
2: 0
1: 0
Practice Yourself :
Q1. Write a C/Java/C++/Python program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following:
Percentage greater than equal 90% : Grade A
Percentage greater than equal 80% : Grade B
Percentage greater than equal 70% : Grade C
Percentage greater than equal 60% : Grade D
Percentage greater than equal40% : Grade E
Percentage less than 40% : Grade F
Q2. Write a C/Java/C++/Python program to input basic salary of an employee and calculate its Gross salary according to following:
Basic Salary less than equal 10000 : HRA = 20%, DA = 80%
Basic Salary less than equal 20000 : HRA = 25%, DA = 90%
Basic Salary greater than 20000 : HRA = 30%, DA = 95%
Write a C/Java/C++/Python program to input electricity unit charges and calculate total electricity bill according to the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill
Instagram: techtalk_debu
Thanks & Regards,
Debu Paul