Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Chapter 2 project 13 on page 106. \"Problem solving and program design in C 8th

ID: 3879358 • Letter: C

Question

Chapter 2 project 13 on page 106. "Problem solving and program design in C 8th edition". I'm not sure how to write the code to where it counts 12 apples and puts them into bags and display the number of bags and remaining apples. Write a program that predicts how many whole bags of apples can be produced given the number of apples available. Assume that each bag holds a dozen apples. Prompt the user to enter the number of apples available. Echo print the number of apples available and then display both the number of bags that will be produced and the number of apples that will be left over. The language is in "C"

Explanation / Answer

#include "stdio.h"

int main(void) {
  
// DECLARING variable apples that holds number of apples
int apples;
  
// taking user input
printf("Enter number of apples: ");
scanf("%d",&apples);
  
// calculating bags. Dividing apples by 12 will give the number of bags we require
int bags = apples / 12;
  
// modulo % operator gives the remainder when divided which gives us the left over apples
apples = apples % 12;
  
// printing output
printf("Bags = %d ",bags);
printf("Remaining apples = %d ",apples);
  
return 0;
}

/*SAMPLE OUTPUT

Enter number of apples: 20
Bags = 1
Remaining apples = 8

Enter number of apples: 107
Bags = 8
Remaining apples = 11

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote