Math Functions (2337)

You might also like

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

NAME : Bhairi Vinaykumar

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>

using namespace std;

int main() {

int X; // Number of students

int Y; // Number of chairs Chef already has

cout << "Enter the number of students: ";

cin >> X;

cout << "Enter the number of chairs Chef already has: ";

cin >> Y;

int newChairs = 0; // Number of new chairs Chef must buy

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

cout << "Enter the cost of one ticket: ";


cin >> X;

int total_cost = 4 * X; // Total cost of the tickets for the four friends

if(total_cost <= 1000) {


cout << "They will be going to the concert." << endl;
} else {
cout << "They will not be going to the concert." << endl;
}

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

cout << "Enter Chef's earnings: ";


cin >> X;

cout << "Enter Chefina's earnings: ";


cin >> Y;

int donation = 0; // Amount to be donated

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;

int total_distance = 2 * X * 5; // Total distance Chef travels in a week

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

cout << "Enter the number of patties: ";


cin >> A;

cout << "Enter the number of buns: ";


cin >> B;

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.

You might also like