add chapter 2 questions
This commit is contained in:
parent
71975c1070
commit
426529e956
|
@ -0,0 +1,34 @@
|
|||
Exercise 2.4
|
||||
|
||||
1. Write statements to copy the array Next into the array Pascal.
|
||||
|
||||
-- Question: is there a 'Length' function call?
|
||||
for I in 0 .. 10 loop
|
||||
Pascal(I) := Next(I);
|
||||
end loop;
|
||||
|
||||
2. Write a nested loop to compute all the rows of Pascal's triangle in
|
||||
the two-dimensional array Pascal2.
|
||||
|
||||
for Row in 1 .. 10 loop
|
||||
Pascal2(Row, 0) := 1
|
||||
for Col in 1 .. Row-1 loop
|
||||
Pascal2(Row, Col) := Pascal2(Row-1, Col-1) + Pascal2(Row-1, Col);
|
||||
end loop;
|
||||
Pascal2(Row, Row) = 1;
|
||||
end loop;
|
||||
|
||||
3. Declare a type Month_Name and then declare a type Date with components
|
||||
giving the day, month, and year. Then, declare a variable Today and assign
|
||||
Queen Victoria's date of birth to it (or your own).
|
||||
|
||||
type Month_Name is range 1 .. 12;
|
||||
type Date is
|
||||
record
|
||||
Day: Integer; -- maybe restrict to maximum day?
|
||||
Month: Month_Name;
|
||||
Year: Integer;
|
||||
end record;
|
||||
Today: Date;
|
||||
Today := (Day => 14, Month_Name => 9, Year => 2019);
|
||||
|
Loading…
Reference in New Issue