In the following code we would like to compute a grade as a percentage #include
ID: 3594254 • Letter: I
Question
In the following code we would like to compute a grade as a percentage #include int main (void) 2 3 5 6 7 int ptotal-80; int ppossible-100; float score; ore=ptotal/Ppossible*100 printf ("The grade is %4.1f%% " , score) ; return 0; 9 10 The student should get an 80%. But this is the output. The grade is 0.0% we can fix line 7, as numbered above, to generate the correct output of 80%. There are many ways. which of the following alternatives to line 7 will show the output at 80%? Please select ALL correct answers score-ptotal/ppossible 100.; score- 100. *ptotal/ppossible score-100 (float)ptotal/ppossible; score-ptotal/ppossible*100.; score-100 ptotal/ppossible score-(float) 100*ptotal/ppossible;Explanation / Answer
1. score-ptotal/ppossible 100.;
2. score- 100. *ptotal/ppossible;
3. score-100 (float)ptotal/ppossible;
4. score-ptotal/ppossible*100.;
5. score-100 ptotal/ppossible;
6. score-(float) 100*ptotal/ppossible;
The code prints 0.0% as ptotal/ppossible, which are both integers outputs an integer = 0 due to the / operator.
#2 score=100.*ptotal/ppossible outputs 80% //100 is written as 100. which makes it a floating point and outputs a floating point
#3 score=100 * (float) ptotal/ppossible ouputs 80% //we explicitly type cast the integer to a floating point
#6 score=(float) 100*ptotal/ppossible outputs 80% //we explicitly type cast the integer to a floating point by writing (float)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.