Question
6. What is wrong here? Happy Hacker likes to write code but he doesnt like to study the theory. He wrote the following chunks of
6. What is wrong here? Happy Hacker likes to write code but he doesnt like to study the theory. He wrote the following chunks of code and was puzzled why they didnt work. Can you help Happy? (a) This loop should generate a hundred thousand random numbers between 0 and 99 and count the 99s. But it doesnt stop, why? short n, targets, k; for(targets = k = 0; k<100000; ++k ) { n = rand() % 100; if (n == 99) ++targets; } (b) Happys loop should print a table of values of sin(x), where x goes from 0 to 1 in steps of 0.01. But it doesnt stop, why? double x = 0; while (x != 1) { printf( "%9.6f ", sin(x) ); x += .01; } (c) Happy used a float variable, star, to store the distance from here to the edge of our galaxy (74,000 light years away), in miles. One light year is 5.879e+12 miles. He used another float variable, mall, to store the distance from here to the nearest shopping mall, in miles. He cant understand why star + mall is the same value as star. Help him; explain why.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started