Vous êtes sur la page 1sur 2

Table of Contents

................................................................................................................................. 1
time .......................................................................................................................... 1
Problem03 ................................................................................................................. 1
Problem04 ................................................................................................................. 1

%{
TITLE: HW03
NAME: KEN KOSTENBADER
RECITATION SECTION: REC04
COLLABORATORS: N/A
%}

time
datestr(now)
%The Datestring function analyzes date and time vectors and organizes
%them into a date format, in the form of strings.
%Unless otherwise specified, datestr will organize the strings into
%the standard format 'dd-mmm-yyyy HH:MM:SS' such as:
%27-Oct-2010 21:18:33
%Using the (now) specification with the Datestring function gets the
%function to analyze the date and time at the present moment (when the
%program is run, displaying it as indicated above (unless otherwise
%specified, for example "datestr(now,2)")

ans =
29-Oct-2010 18:46:07

Problem03
disp('Problem 3 - ANSWER')
%we begin with p at the absolute smallest 8-digit number
p=10000000;
%we start with a flag (t) turned off
t=0;
while (t==0)
p=p+1;
%until the flag is turned on, our number increments by +1
t=isprime(p);
end
fprintf('The smallest 8 digit prime number is %.0f. \n',p)

Problem 3 - ANSWER
The smallest 8 digit prime number is 10000019.

1
Problem04
disp('Problem 4 - ANSWER')
%first we define each element in the structure array
student(1).Name = 'Ginny';
student(1).Age = '18';
student(1).Major = 'Biological Sciences';
student(2).Name = 'Frank';
student(2).Age = '20';
student(2).Major = 'Biomedical Engineering';
for x=1:2
a=student(x).Name;
b=student(x).Age;
c=student(x).Major;
fprintf('%s is %s years of age is studying %s \n',a,b,c)
end

Problem 4 - ANSWER
Ginny is 18 years of age is studying Biological Sciences
Frank is 20 years of age is studying Biomedical Engineering

Published with MATLAB® 7.10