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

1. Write a program that computes the volume of a box. The function main in the p

ID: 3535979 • Letter: 1

Question

1. Write a program that computes the volume of a box. The function main in the program calls a function to read the length, width and height of the box from the keyboard. The program then uses another function to compute the volume of the box:
(volume = length * width * height). The computed volume is to be printed from the function main. No global variables are allowed (have to use parameters in the functions).

2.What would be printed from the following program segment:

for (int x = 10 ; x > 7 ; x--)
printf ( "%d ", x ) ;Answer

On separate lines: 10 9 8 On separate lines: 10 10 10 On same line: 10 9 8 On same line: 8 9 10 3. a. Write a program that uses a for loop to read 10 integers. The program computes and prints the sum and average of all the integers.
b. Rewrite the same program using a do-while loop to compute and print the sum and average of the integers . Answer

Explanation / Answer

1. Voluem of Box



/*
* File: sum.c
* Author: Krishna
*
* Created on 11 May, 2013, 8:30 AM
*/

#include <stdio.h>
/*
*
*/

float calculateVolume(double length, double width, double height) {
return (length * width * height);
}

// gets input and clculates volume

float PrintVolume() {
float lenght, width, height, volume;
printf("enter length, width, height values");
scanf("%f", &lenght);
scanf("%f", &width);
scanf("%f", &height);
volume = calculateVolume(lenght, width, height);
return volume;

}

int main(int argc, char** argv) {
printf("%f", PrintVolume());
return 0;
}







2. Prints on separate lines 10 9 8


3. A

#include<stdio.h>
int main(int argc, char** argv) {

int i = 0, sum = 0, n;

float avg;
printf("Enter 10 integers to find sum and average");
for (i = 0; i < 10; i++) {
scanf("%d", &n);
sum = sum + n;
}
avg = sum / 10.0;
printf("%f", avg);
return 0;

}



3. B


#include<stdio.h>
int main(int argc, char** argv) {

int i = 0, sum = 0, n;

float avg;
printf("Enter 10 integers to find sum and average");
do{
scanf("%d", &n);
sum = sum + n;
i++;
}while(i<10);
avg = sum / 10.0;
printf("%f", avg);
return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote