Professional Documents
Culture Documents
Math Functions (2337)
Math Functions (2337)
Math Functions (2337)
ROLL NO : 2337
DIV : C ( C2 )
S.Y MECHANICAL
SUB : C++ PBS
TOPIC : MATH
Problem Statement 1:
Chef's coding class is very famous in Chefland. This year X students joined his class
and each student will require one chair to sit on. Chef already has Y chairs in his
class. Determine the minimum number of new chairs Chef must buy so that every
student is able to get one chair to sit on.
Code:
#include<iostream>
int main() {
cin >> X;
cout << "Enter the number of chairs Chef already has: ";
cin >> Y;
if(X > Y) {
newChairs = X - Y;
cout << "Chef must buy " << newChairs << " new chairs." << endl;
return 0;
}
Output:
Problem Statement 2:
Four friends want to attend a concert. Each ticket costs X rupees. They have decided
to go to the concert if and only if the total cost of the tickets does not exceed 1000
rupees. Determine whether they will be going to the concert or not.
Code:
#include<iostream>
using namespace std;
int main() {
int X; // Cost of each ticket
int total_cost = 4 * X; // Total cost of the tickets for the four friends
return 0;
}
Output:
Problem Statement 3:
In a certain month, Chef earned X rupees while Chefina earned Y rupees such that
Y>X. Since they want to end up with exactly the same amount, they decide to
donate the difference between their income to a charity. Find the amount they
donate in the month.
Code:
#include<iostream>
using namespace std;
int main() {
int X; // Chef's earnings
int Y; // Chefina's earnings
if(Y > X) {
donation = Y - X;
}
cout << "They donate " << donation << " rupees in the month." << endl;
return 0;
}
Output:
Problem Statement 4:
Chef wants to become fit for which he decided to walk to the office and return home
by walking. It is known that Chef's office is X km away from his home. If his office
is open on 5 days in a week, find the number of kilometers Chef travels through
office trips in a week.
Code:
#include<iostream>
using namespace std;
int main() {
int X; // Distance of Chef's office from his home in km
cout << "Enter the distance of Chef's office from his home in km: ";
cin >> X;
cout << "Chef travels " << total_distance << " km through office trips in a week." << endl;
return 0;
}
Output:
Problem Statement 5:
Chef is fond of burgers and decided to make as many burgers as possible. Chef has
A patties and B buns. To make 1 burger, Chef needs 1 patty and 1 bun. Find the
maximum number of burgers that Chef can make.
Code:
#include<iostream>
using namespace std;
int main() {
int A; // Number of patties
int B; // Number of buns
int burgers = min(A, B); // Maximum number of burgers Chef can make
cout << "Chef can make " << burgers << " burgers." << endl;
return 0;
}
Output:
Conclusion:
We’ve understand the math function in C++ coding language and the importance of the math functions.