pascal triangle program

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


Please Help Members By Posting Answers For Below Questions

Define macros.

1017


What do you mean by command line argument?

821


What is array in c with example?

863


In C language what is a 'dangling pointer'?

827


Linked lists -- can you tell me how to check whether a linked list is circular?

847


What is pointer to pointer in c?

842


What is storage class?

842


how to print the character with maximum occurence and print that number of occurence too in a string given ?

2234


What is structure data type in c?

739


Differentiate between Macro and ordinary definition.

971


simple program of graphics and their output display

1689


Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record

4969


Is it fine to write void main () or main () in c?

734


Do you know the purpose of 'register' keyword?

811


How macro execution is faster than function ?

867