jbo214hw2 - y = 0.49688 k = 6 x = 0.216667 y = 0.419898 k =...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
**************************************** Joshua Okrent 819710517 9/21/2010 HW # 2 Khadija Benjilali Section 12 **************************************** 2.24 Solution: counter = 0, 2*0=0=x, 0=y counter = 1, 2*1=2=x, tan(2)=-2.18503=y counter = 2, 2*2=4=x, tan(4)+tan(2)=-1.02722 counter = 3 3*2=6=x, tan(6)+tan(4)+tan(6)=-1.31822 counter = 4 end of loop Output: Counter = 0 x=0 y=0 Counter = 1 x=2 y=-2.18504 Counter = 2 x=4 y=-1.02722 Counter = 3 x=6 y=-1.31822 Counter= 4 2.34 Solution: I=2 J=i+1 K=remainder of 4/j Until I is equal to 4 I = (2+1) J = 2 K =2/4 r 2 I = (3+1) J =(I+1)=3 K =3/4 r1 I = (4+1) J =(I+1)=4 K = 4/4 r0
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Output: i = 3 j = 2 k = 2 i = 4 j = 3 k = 3 i = 5 j = 4 k = 0 2.36 Solution: K =3 x =1.3/3 y=sin(2*1.3/3) K =4 x =1.3/4 y=sin(2*1.3/4) K =5 x =1.3/5 y=sin(2*1.3/5) K =6 x =1.3/6 y=sin(2*1.3/6) K =7 end of loop Output: k = 3 x = 0.43333 y = 0.762175 k = 4 x = 0.325 y = 0.605186 k = 5 x = 0.26
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: y = 0.49688 k = 6 x = 0.216667 y = 0.419898 k = 7 2.42 Solution: K=2 x= sqrt(4-2) y=2 K=4 x= sqrt(6) y=5 K=5 x=sqrt(3) y=3 Output: k = 2 x = 1.41421 y = 2 k = 4 x = 2.44949 y = 5 k = 5 x = 1.73205 y =3 2.44 Identify the errors in the following C++ program file: using namespace std; #include<iostream>; (no semicolon needed) int main() { double x; int k; x=8. do while (k<6) (while (k<6) should be placed after the curly bracket) { k++ (needs semicolon) if(k<5) { x=++k; k=x; } cout>>"x is equal to ", x<<endl; (arrows are pointed wrong direction, need arrows to separate statement and x, need to place comma inside quotations) system("pause"); return 0; ) (needs to be a curly bracket not a parentheses) What will be the output of the program, when corrected (if k=1 initially) ? Output=8...
View Full Document

This note was uploaded on 10/09/2011 for the course ENGR 1 taught by Professor X during the Fall '07 term at Lehigh University .

Page1 / 3

jbo214hw2 - y = 0.49688 k = 6 x = 0.216667 y = 0.419898 k =...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online