This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 1 14:440:127 Introduction to Computers for Engineers Recitation 05 Problems  Pertaining to LEC05 Notes Rutgers University, Spring 2011 Instructor  Brenda V. Cortez INSTRUCTIONS: You can create a separate Mfile for each of the problems in your recitation problem sets, so that you can reference back to your answers later when you study. Save all your work to your MATLAB Files directory in the J: Drive. An alternative to separate MFiles, is to create a single Mfile for all the problems, and use %% to create a cell for each problem. Refer to my Video Tutorial on the topic of cells found in Video Tutorials > LEC04 Video Tutorials . For all problems, always think about using good variable names, even if the problem doesnt explicitly specify variable them; get used to defining your own. Make sure you go through all the problems before the exam and ask any questions if you dont understand why something works the way it does. I suggest that you write simple pseudocode stating the algorithm you will use to solve each problem that requires a program. Then start typing your code. It may save you from errors. PROBLEMS: 1. Rewrite the following if statement as a switch statement if(x==5  x==6) disp(one) elseif(x==7) disp(two) else disp(three) end 2. Write Matlab code that finds the sum of all prime numbers from 211 to 300 , inclusive. ( inclusive means it includes 211 and 300 ). Display your answer, using fprintf , in the following format (inserting the correct answer from your calculations into the underlined por tion): The sum of all primes from 211 to 300 is 4048 . 3. Assume that there already exists a matrix stored in the variable A . (To test your solution, you should make up your own matrix and store it as A ). Write MatLab code that, for any matrix stored in A , calculates and displays the sum of all composite numbers in that matrix. Note that composite numbers are those that are not prime (Hint: if you test if they are prime ( isprime ), Matlab returns false). 2 4. Ask the user to input a number. Do the following: If the number is a positive, prime integer, display Prime! If the number is a positive, composite integer, display Composite! If the number is a negative integer, display Negative If the number is zero, display Zero In all other cases, display Not an integer Hint: make use of the fix function in your answer. 5. The Body Mass Index (BMI) is mathematically = Weight in Kg /(Height in meters) 2 . Write code to take input ask the user to enter his/her weight in pounds and height in inches, and display whether the person is he/she is underweight (BMI < 18), normal(BMW is 1825) or overweight (more than 25). Hint: you need to look up the inches to meters conversion....
View Full
Document
 Spring '08
 Finch

Click to edit the document details