For C code: Do not use any function other than getchar, scanf, and printf Q2.A) Write a...

50.1K

Verified Solution

Question

Programming

For C code: Do not use any function other than getchar, scanf,and printf

Q2.A) Write a programto do the following: Read in two values intovariables X   and y from the keyboard (they may bedecimal values like 2.3). Read in a 3rd value (which isreally small < 1.0 ) into variable E. Using a loop find out thevalue of N in the below expression. i.e. Each iteration of the loopreduced the value of Y by dividing it by 2. Print out N at the endwhen the condition is met. For most input X and Y values thecondition may not become true and the loop would become an infiniteloop. To break from such \"traps\", you can have a loop count andbreak away. i.e. Count how many iterations it has run through theloop body, and if it goes over some number, say 100, just use\"break\" after saying \"there is no solution for the given numbers\"which should end the program.  

Note: This program conveys the convergence vs divergence innumerical methods.

(a) Let X = 1.02 Y = 8.1, E = 0.05. In each iterationY/2N values become 8.1, 4.05, 2.025, 1.0125, and stopssince X - 1.0125 is 0.0075 which is < E. This starting Y valueconverges toward a solution.

(b) If X = 1.02 and Y = 9.5, then it would not converge to asolution to meet the criterion, but diverges away.Y/2N value become 4.75, 2.375, 1.1875, 0.59375,0.2968,goes to 0, but difference goes up.   

Answer & Explanation Solved by verified expert
4.1 Ratings (511 Votes)
code in c code to copyinclude include int mainint argc char argv declare variables float xye read user input scanff f f x y e    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