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

Assignment Smq1024

The document provides instructions for an assignment involving writing Scilab code to solve 3 problems and submitting the results. Problem 1 asks students to write code to calculate the volume and surface area of a sphere given its radius. Problem 2 asks students to write code to calculate a person's BMI given their weight and height and classify it as underweight, healthy, or overweight. Problem 3 asks students to write code to compute and output the Fibonacci sequence up to the nth term provided by the user. Students are instructed to include the code and output in a Word document and submit it by a deadline.

Uploaded by

Nurul
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)
52 views4 pages

Assignment Smq1024

The document provides instructions for an assignment involving writing Scilab code to solve 3 problems and submitting the results. Problem 1 asks students to write code to calculate the volume and surface area of a sphere given its radius. Problem 2 asks students to write code to calculate a person's BMI given their weight and height and classify it as underweight, healthy, or overweight. Problem 3 asks students to write code to compute and output the Fibonacci sequence up to the nth term provided by the user. Students are instructed to include the code and output in a Word document and submit it by a deadline.

Uploaded by

Nurul
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
You are on page 1/ 4

ASSIGNMENT 1

Name:Nurul Syuhada Bt Ahmat Samsuri.

Matric No: E20111002834

Lect. Name: annie gorgie


Instruction: For each of the questions given below, you need to write a

simple code using a script file. Submit to me the softcopy of your results.
The softcopy should be a written report done in Microsoft Word that consists
of the script files and output on each questions. The submission is done via
MyGuru2. The assignment is due on Friday, 1 February 2013 at 4pm. You
are required to write the code on your own. You may discuss with your friend
but if you are caught copying others work, no marks will be given to both
party.

1. Write a program to calculate the volume and surface area of a sphere,


given its radius as an input. To printout the output, you may need to
use the following command:

mprintf(’\n volume= %f and \n area = %f’,volume, area);

Here are some useful formulae V = 4/3r^3 and A = 4r^2.

[10 marks]

Answer:

Code:-

r=input("enter the value of radius: ")


volume=(4/3)*%pi*(r^3)
area=4*%pi*(r^2)
mprintf("\n volume= %f and \n area = %f",volume, area);

console:

enter the value of radius: 2

volume= 33.510322 and


area = 50.265482
2. A persons body mass index is calculated by taking their weight in
kilograms divided by their height in meters, squared. A BMI in the
range of 1925 (inclusive) is generally considered healthy. Below 19 is
considered underweight, above 25 overweight. Write a Scilab script that
calculates a person’s BMI and displays it, along with an indication of
whether they are below, in, or above the healthy range. Use mprintf
to display the output. For example, the output should display as

What is your weight in kilograms? 60


and height in centimetres? 160
Your BMI is 23.4. This is considered normal.

[10 marks]

Answer:

Code:-

weight=input("what is your weight in kilogram?: ")


height=input("height in metre?:")
BMI=weight/(height*height)

if (BMI<19) then
y=(' considered underweight');
elseif (BMI>=19) & (BMI<=25)
y=('considered healthy ');
elseif (BMI>25)
y=('considered overweight');
end
mprintf('your BMI is %i,this is %s.\n',BMI,y);

console:

what is your weight in kilogram?: 50


height in metre?:1.5
your BMI is 22,this is considered healthy .
3. The Fibonacci sequence starts 1, 1, 2, 3, 5, 8, . . .. Each number in the
sequence (after the first two) is the sum of the two previous numbers.
Write a Scilab script that computes and outputs the numbers in the
sequence up to the nth number, where n is a value provided by the user.

[10 marks]

Code:-

term = input('enter number of term of Fibonacci? ');


if term >= 1 & term >=2
mprintf('The first %i numbers are: 1', term);
end

n1 = 1;
n2 = 1;
for count = 3:term
fib = n1 + n2;
mprintf(', %i', fib);
n2 = n1;
n1 = fib;
end
mprintf('.\n');

console:

enter number of Fibonacci do you want? 10


The first 10 numbers are: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55.

You might also like