Programming For Engineers

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Write a MATLAB function that:

1. Asks the user to choose one type of coffee out of three choices.
2. Tells the user what is the price of that coffee when its chosen and asks for amount of money
3. Tells the user that the money he or she entered is enough, more than enough and should get back some change less
than required and should give more

Example 1 , how the function work:


myCoffee
Please choose one of our coffees (1. Esspreso, 2. Nesscafe, 3. Cappucino) : 1
You have choosed Esspreso, the price is 2 euros, please pay the amount: 5
You paid extra money, 3 euros is the change.

Example 2 , how the function work:


myCoffee
Please choose one of our coffees (1. Esspreso, 2. Nesscafe, 3. Cappucino) : 3
You have choosed Cappucino, the price is 3 euros, please pay the amount: 1
You paid less money, 2 euros more required.

Write a MATLAB function that asks the user to enter series of 3 numbers and tells the user which numbers where
entered first and which number last and which number second.

Example how the function work

myPalmReader
enter series of numbers in square brackets [ ] : [7 3 9]
you entered 7 first, 9 last and 3 second

Write a MATLAB function that takes numbers and sort them form bigger to smaller

Example how the function work

mySorter( 13, 20, 17)


your numbers from big to small
20
17
13

Repeat the previous example by asking the user to enter the numbers, not making them arguments of the function
Write a MATLAB function that takes 2 numbers and gives back the first times the second if the first is smaller, and the
first divided by the second if the first is larger, and gives their addition if they are equal
Examples
myCrazyNumber(4,7)
your result is:
32 (this comes from 4*7 )

myCrazyNumber(4,2)
your result is:
2 (this comes from 4/2 )

myCrazyNumber(4,4)
your result is:
8 (this comes from 4+4 )

Loops

Write a MATLAB loop to list all numbers less than 1000 that can be divided by 4 without reminders.

Write a MATLAB loop to add all odd numbers between 10 and 1010

Write a MATLAB loop that asks the user to enter a number until he finds his lucky number
Example
Enter a number: 3
Not lucky, enter a number: 2
Not lucky, enter a number: 5
Not lucky, enter a number:6
Not lucky, enter a number: 4
Not lucky, enter a number: 7
Lucky YOU

You might also like