092.动态数组

with Ada.Text_IO,Ada.Integer_Text_IO;
use Ada.Text_IO,Ada.Integer_Text_IO;

procedure Summer is
   
   type MY_ARRAY is array (Positive range <>) of Integer;
   
   Dummy1:constant MY_ARRAY:=(27,14,13,33);
   Dummy2:constant MY_ARRAY:=(112=>24,113=>14,114=>13,115=>33);
   
   My_List:MY_ARRAY(1..12);
   Stuff:MY_ARRAY(4..11):=(12,13,7,11,125,others=>17);
   Total:Integer;
   
   function Sum_Up(In_Array:MY_ARRAY)return Integer is
      Sum:Integer:=0;
   begin
      for Index in In_Array'First ..In_Array'Last loop
         Sum:=Sum+In_Array(Index);
      end loop;
      Put("the sum of the number is:");
      Put(Sum,4);
      New_Line;
      return Sum;
   end Sum_Up;
   
   
   
begin
   My_List := (0, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 7);
   Stuff := (4 => 12, 8 => 11, 5 => 13, 7 => 1, others => 9);

   Total := Sum_Up(My_List);
   Total := Sum_Up(Stuff);
end Summer;
   
   
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值