0% found this document useful (0 votes)
4 views4 pages

Write A Matlab Program Exercise 2

The document outlines a series of MATLAB programming tasks, including calculating the area of a circle, checking integer equality, converting temperatures between Celsius and Fahrenheit, calculating electricity bills based on unit consumption, and applying discounts based on pricing codes. It also includes programs for summing series, counting odd/even numbers, and analyzing a given vector for positive and negative numbers. Each task specifies user prompts and the necessary calculations to be performed.

Uploaded by

maborambo58
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Write A Matlab Program Exercise 2

The document outlines a series of MATLAB programming tasks, including calculating the area of a circle, checking integer equality, converting temperatures between Celsius and Fahrenheit, calculating electricity bills based on unit consumption, and applying discounts based on pricing codes. It also includes programs for summing series, counting odd/even numbers, and analyzing a given vector for positive and negative numbers. Each task specifies user prompts and the necessary calculations to be performed.

Uploaded by

maborambo58
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Write a matlab program that prompts user to


input the radius of circle and it calculates area and
displays area of circle.

2. Write a matlab program to accept two integers


and check whether they are equal or not.

3. Write a matlab program for conversion of Celsius


to Fahrenheit or vice versa.
The program prompts user for type of conversion
and the temperature input. It calculates the result
and displays the output.

type
F : to convert from Celsius to Fahrenheit

C : to convert from Fahrenheit to Celsius

Celsius to Fahrenheit conversion formula

Fahrenheit = (Celsius * 1.8) + 32


Fahrenheit °F to Celsius °C Formula
°C = (°F - 32) ÷ (9/5)

4. Write a program to calculate the electricity bill of


the customer. The program prompts user to input
customer name and unit consumed. Then it
calculates and displays the total amount to pay to
the customer. The charges are shown below:

unit Charge per unit


Upto 199 $1.20
200 - 400 $1.50
401 - 600 $1.80
Above 600 $2.00

5. Write a program that will prompt user for the price of an


article and a pricing code. Your program is then to
calculate a discount rate according to the pricing code
and print to the screen the original price of the article,
the discount amount and the new discounted price.
Calculate the pricing code and accompanying discount
amount as follows:
Pricing code Discount rate
H 50%
F 40%
T 33%
Q 25%
Z 0%
others invalid pricing code

If the pricing code is Z, then the words ‘No discount’ are to


be printed on the screen. If the pricing code is not H, F, T,
Q or Z then the words ‘Invalid pricing code’ are to be
printed.

8. Write a program for following expression


15

∑i
i=1

Sum of the series


1+2+3+4+….+15

9. Write a program for following expression


50

∑ n2
20

Where n is even number.


202 + 222 + 242 + 262 +……+ 502

10. Write a program for following expression


3

∑ (2 n−1)2
13

Where n is odd number.


(2*13-1)2 + (2*11-1)2 +(2*9-1)2 + (2*7-1)2 +……+ (2*3-1)2

11. Write a program that prompts user to input


numbers till user wants and at the end it should display
the count of odd, even and zeros entered.

12. Write MATLAB code to calculate the following of the


given vector A.
A= [20, 65, -4, 5, 90, -15, 10, 30, -3, 52, 64, -14, -
17, 18, 33, 48, -23];
Display
(i) The count, total and the average of the positive
numbers.
(ii) The count total and the average of the positive
numbers.

You might also like