Recitation 07 Presentation

# Recitation 07 Presentation - 14:440:127 Introduction to...

This preview shows pages 1–6. Sign up to view the full content.

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 14:440:127 Introduction to Computers for Engineers Recitation 7 Lecturer: Blase E. Ur Recitation Instructor: Bo Jin Recitation Instructor: Cyrus Gerami Recitation Instructor: Vishnu Vijayakumar Recitation Instructor: Wen Yueh 14:440:127 Recitation 7 WHILE LOOPS Convert a FOR loop 1) Initialize variable 2) Condition 3) Increment for x = 1:2:15 x = 1; % step 1 for x = 1:2:15 x = 1; % step 1 disp(x) while(x<=15) % step 2 end disp(x) x = x + 2; % step 3 end 14:440:127 Recitation 7 LOOPS Twin Primes tic for x = 1001:2:9997 if(isprime(x) & isprime(x+2)) fprintf('%.0f and %.0f are both prime\n',x,x+2) fprintf('%.0f and %.0f are both prime\n',x,x+2) end end toc %%% Elapsed time is 0.302293 seconds. 14:440:127 Recitation 7 LOOPS tic x = 1001; while(x<=9997) if(isprime(x) & isprime(x+2)) fprintf('%.0f and %.0f are both prime\n',x,x+2) fprintf('%.0f and %.0f are both prime\n',x,x+2) end x = x + 2; end toc %%%% Elapsed time is 0.444185 seconds. 14:440:127 Recitation 7 LOOPS tic x = 1001:2:9997; twins = x(isprime(x) & isprime(x+2)); printout = [twins; twins+2]; fprintf(ā%.0f and %.0f are both prime\nā, printout)fprintf(ā%....
View Full Document

{[ snackBarMessage ]}

### Page1 / 22

Recitation 07 Presentation - 14:440:127 Introduction to...

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

View Full Document
Ask a homework question - tutors are online