answer please
HIT365 – C Programming
Quiz 1
This quiz is worth 15% of the total unit. It is a closed book exam. Computers and
calculators are not allowed in the quiz.
Instruction
The quiz of this unit will be held on line. The time and date of the quiz are as per unit
information.
Date: 16th April 2021
Time: 3:30pm to 5:30pm
Upload scanned *.pdf document with your answers before 7pm 16th April 2021. You can
submit photos taken with a mobile phone (put them in one Word file and save the Word file
as a pdf file), provided the prints of the photos are readable.
You must complete this quiz without the assistance of other persons and without the use of
materials and/or aids which are not explicitly listed on the front cover of the quiz (including
internet searches during the quiz times).
To get ready for the test
- Have sufficient blank pages available to write your answers on (20 pages recommended)
- Have sufficient blue or black pens available
Start the quiz
The quiz will be released in pdf format in Learnline at the specified start time and date of the
test. You can read the quiz as a pdf from a screen, or you can print the document and work
from the printed document.
Finish the quiz and submit
Stop writing at the finish time mentioned above. Then proceed to scan your document and
upload it to Learnline. You should complete uploading the document within 1 hour of the
finish time of the quiz.
Assistance during the test
Your lecturer will be available via email during the quiz time. If you have any questions
during the quiz or problems with completing or submitting your document, please email your
lecturer immediately.
Declaration
Please note that by submitting the document of this assessment, you declare that all materials
in your document is your own work except where there is a clear acknowledgement and
reference to the work of others. You also declare that you have read the University's
Academic and Scientific Misconduct Policy and understand its implications.
Question 1 (3 marks)
Draw a flowchart and write a C program to check whether a given number is even or odd.
Question 2 (2 marks)
Write a C program to check two given integers whether either of them is in the range
100...200 inclusive.
Question 3 (2 marks)
Write a C program that allows the user to enter the radius of a sphere, calculates the sphere
volume and displays the result. The volume of a sphere is V = 4/3*π*r3 where r is the radius
of the sphere.
Question 4 (1 mark)
Is there a problem in the following program? If yes then what is it?
#include <stdio.h>
int num;
int main(void) {
while ( num <= 100 ) {
num = 3 * num;
}
printf(“%d”, num);
}
Question 5 (2 marks)
Explain, using your own words, the purpose of putting "(float)" in front of the variable
"total" in the following program.
#include <stdio.h>
int main(void)
{
unsigned int counter;
int grade;
int total;
float average;
total = 0;
counter = 0;
printf( "%s", "Enter grade, -1 to end: " );
scanf( "%d", &grade );
while ( grade != -1 ) {
total = total + grade;
counter = counter + 1;
printf( "%s", "Enter grade, -1 to end: " );
scanf("%d", &grade);
}
if ( counter != 0 ) {
average = ( float ) total / counter;
printf( "Class average is %.2f\n", average );
}
else {
puts( "No grades were entered" );
}
}
Question 6 (3 marks) Write a program in C that contains a function which receives two floating point numbers from the main function and returns the difference of the two floating point numbers to the main function. The main function prints the result in three decimal places.
Question 7 (2 marks) In the following program, explain in detail, using your own words, the “while” loop condition. If the user enters “A”, what does the variable “grade” store? #include <stdio.h> int main(void) { int grade; unsigned int aCount = 0; unsigned int bCount = 0; puts( "Enter a character." ); while ( ( grade = getchar() ) != EOF ) { switch ( grade ) { case 'A': case 'a': ++aCount; break; case 'B': case 'b': ++bCount; break; default: printf( "%s", "Incorrect letter grade entered." ); puts( " Enter a new grade." ); break; } } puts( "\nTotals for each letter grade are:" ); printf( "A: %u\n", aCount ); printf( "B: %u\n", bCount ); }