Answered step by step
Verified Expert Solution
Question
1 Approved Answer
02:54 1_Lab Report 5.doc QQ R C program to find sum of even number from 1 to N.Logic to find sum of even numbers. Step
02:54 1_Lab Report 5.doc QQ R C program to find sum of even number from 1 to N.Logic to find sum of even numbers. Step by step descriptive logic to find sum of even numbers 1. Input upper limit to find sum of even number Store it in some variables ay N 2. Initialize another variable to store sum with say sum = 0. 3. To find sum of even numbers we need to test through numbers rom 1 ton. Initialize a loop from 2 to Nand increment 2 on each iteratio 4. Inside the loop body add previous value of sun with i.e. sumsum + 5. After loop print final value of sum The execution of the program should be like the following Remuan : 1 yetu alue 14 FICERE EXiced at S... 32 Task Two! For loop practice The Fibonacci numbers or Fibonacci sequence are the numbers in the follo wing integer sequence, F0-0,F1-1. FreFn. 1 n 2 in2.nEN): Use a for loop to implement the task. Logic to print Fibonacci series up to n te Step by step descriptive logic to print n Fibonaca terms 1. Input number of F aces to print from user Sort in a variable sayem 2. Declare indicate the variables, cal Fibonacci magic initiatization FO- 0,F1=1 and F2-FO+F1. Here F2 is the current F1 is than-1thmand Finchem 3. Run a loop from 1 to terms, Increment loop counter by 1. The loop structure shoul dlook like for 1 ). It will through n bare 4. Inside the loop copy the value of n-1th term 10-2th terme. FO=F1 Next copy th o rnth to 1th term F1-F2. Final compute the new term by adding previous two termale. F2 = F1+FO. 5. Print the of current Fibonacci lemia F2. The motion of the prog e the following Electure_2JUNC Programming 2015-201612 a b-2 How many Fibonacci numbers you want to print out? 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 Gem (FAQ ) 02:54 P 3.2 Task Two: For loop practice The Fibonacci numbers or Fibonacci sequence are the numbers in the follo wing integer sequence, F0:0,F101, Fnafn: 1Fn 2 (na2, nEN): Use a for loop to implement the task. Logic to print Fibonacci series up to n te Step by step descriptive logic to print n Fibonacci tems 1. input number of Fbonacc i rom user Store in a variable say term 2. Declare and in the variables, calkosFbonacci medicinitization FO- O. F11 and F2-FO+F1 Here F2 is the current Flisten them and Foin them. 3. Run a loop from 1 to terms, increment loop counter by 1. The loop structure shoul dlook likefon-1; i++). It wiltrate through n terms 4. Inside the loop copy the value of n-1th team to n2th termia FO-F1 Next copy the value of nth to 1th term F1-F2. Final compute the new term by adding previous two termisie F2-F1+FO 5. Print the value of current Fbonacci termie. F2. The section of the program should be the following ExLecture_ZIUNC Programming 2015-2016121 6 2 HOH many Fibonacci numbers you want to print out? 20 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 3.3 Task Three: Do while loop practice Use a do-while loop and the following formula to calculate the value of 111 4357 Analyze The first approximation start from 4.0 A more precise approximation done by add an item that is 1.0/add nem The sign of the added item is changed to its opposite after each The added item item is incremented by 2 after each addition Il terminales when the approximation doesn't change too much be tween additions Procedure: define variables: piadd item, precision, sign . initiaze variables use proper loop to calculate the sequence precision 1.06 pi+s4 Design 1.0/add item; sign-10: add_item += 2.0 print out the result of The execution of the program should be like the following
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