Answer Posted / sevak.yatrik777
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
with Ada.Text_Io; use Ada.Text_Io;
procedure Pascals_Triangle is
type Row is array(Positive range <>) of Integer;
type Row_Access is access Row;
type Triangle is array(Positive range <>) of Row_Access;
function General_Triangle(Depth : Positive) return
Triangle is
Result : Triangle(1..Depth);
begin
for I in Result'range loop
Result(I) := new Row(1..I);
for J in 1..I loop
if J = Result(I)'First or else J =
Result(I)'Last then
Result(I)(J) := 1;
else
Result(I)(J) := Result(I - 1)(J - 1) +
Result(I - 1)(J);
end if;
end loop;
end loop;
return Result;
end General_Triangle;
procedure Print(Item : Triangle) is
begin
for I in Item'range loop
for J in 1..I loop
Put(Item => Item(I)(J), Width => 3);
end loop;
New_Line;
end loop;
end Print;
begin
Print(General_Triangle(7));
end Pascals_Triangle;
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is #define in c?
What is main () in c?
What are the uses of a pointer?
What is the code for 3 questions and answer check in VisualBasic.Net?
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
How can you return multiple values from a function?
code for replace tabs with equivalent number of blanks
write a program to rearrange the array such way that all even elements should come first and next come odd
What is huge pointer in c?
Here is a good puzzle: how do you write a program which produces its own source code as output?
List a few unconditional control statement in c.
What is the size of enum in c?
What is structure and union in c?
Can we access the array using a pointer in c language?
What is the right type to use for boolean values in c?