Professional Documents
Culture Documents
C Programming Case3
C Programming Case3
Professor Nadech has scheduled a makeup class for the CS102 course in the evening. He thinks that if
the makeup class is scheduled in the evening, students might be hungry because they have been
studying all day.
Therefore, he consulted another instructor, Professor Yanya, expressing a desire to order pizza and
Pepsi to treat the students during the makeup class. However, due to Professor Nadech's limited
budget, he wants to calculate in advance how many students he can afford to treat with pizza.
Based on the information found on the internet, a pizza costs 599 baht per tray, which contains 8 slices.
Professor Yanya wants to help write a program to calculate the pizza orders. The program will receive
the budget as input and calculate the number of students who can be treated to pizza. The program
should ensure that each student gets to have at least 2 slices of pizza. Finally, the program should
display the remaining budget.
For example, if the input budget is 1000 baht, the program should indicate that it can support 4
students, leaving 401 baht.
#include <stdio.h>
int main() {
scanf("%d", &budget);
return 0;
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Explaination
#include <stdio.h>
This line includes the standard input-output library, which is necessary for functions like `printf` and
`scanf`.
2. Main Function:
int main() {
3. Variable Declaration:
Here, we declare variables to store the budget amount, cost per pizza, slices per pizza, and slices per
student. The cost and slices information is provided in the problem statement.
4. Input:
scanf("%d", &budget);
The program prompts the user to enter a budget amount and reads the input using `scanf`.
5. Calculation:
The program calculates the number of students who can be supported and the remaining budget after
purchasing pizzas.
6. Output:
Finally, the program displays the number of students who can be supported and the remaining budget
using `printf`.
7. Return Statement:
return 0;
This program is a basic implementation to calculate the number of students who can be supported with
pizza given a budget. Note that it assumes a simple scenario without considering factors like rounding
slices or providing fractional slices to students. valid.