#include <stdio.h> int main(void) { float funds = 1.0, cost = 0.1; int candies = 0; while(cost <= funds)...

70.2K

Verified Solution

Question

Programming

#include
int main(void) {
float funds = 1.0, cost = 0.1;
int candies = 0;
while(cost <= funds) {
candies += 1;
funds -= cost;
cost += 0.1;
}
printf(\"%d candies with $%.2f left over.\n\",candies,funds);
return 0;
}

When you compile and run this code you get 3 candies with $0.40left over.

Without knowing how floating point numbers work in a computer,would this result be expected? Explain why or why not. Explain whythis result, in fact, occurred.

Answer & Explanation Solved by verified expert
4.1 Ratings (856 Votes)
In the computer system the floatingpoint number is representedby using IEEE floatingpoint representationThe float data type in Programming Language C is    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students