Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6690781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:40:35+00:00 2026-05-26T05:40:35+00:00

How do i check if a certain value is the largest element in an

  • 0

How do i check if a certain value is the largest element in an array? this is in the Ada language. I have the function finding the largest element, and it works.. now i want to run a post condition that check that that value is the largest.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:40:35+00:00Added an answer on May 26, 2026 at 5:40 am

    Loop through the array, failing if you find an element that is larger or if you don’t find an element that is equal?

    function Check_Largest (In_Array : Array_Type; Value : Element_Type)
      return Boolean
    is
       Matched : Boolean := False;
    begin
       for J in In_Array'Range loop
          if In_Array (J) > Value then
             return False;
          elsif In_Array (J) = Value then
             Matched := True;
          end if;
       end loop;
       return Matched;
    end Check_Largest;
    

    Revisiting this in 2020, post Ada 2012, a pair of quantifiers might do the trick; see the postcondition of Largest_Member:

    procedure Largest
    with SPARK_Mode
    is
       type Arr is array (Positive range <>) of Natural;
    
       function Largest_Member (Of_Array : Arr) return Natural
       with
         Pre => Of_Array'Length > 0,
         Post =>
           (for all E of Of_Array => E <= Largest_Member'Result)
           and
           (for some E of Of_Array => E = Largest_Member'Result);
    
       function Largest_Member (Of_Array : Arr) return Natural is
          Result : Integer := -1;
       begin
          for J in Of_Array'Range loop
             if Of_Array (J) > Result then
                Result := Of_Array (J);
             end if;
             pragma Loop_Invariant
               ((for all F of Of_Array (Of_Array'First .. J) => F <= Result)
                and
                (for some F of Of_Array (Of_Array'First .. J) => F = Result));
          end loop;
          return Result;
       end Largest_Member;
    begin
       null;
    end Largest;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to check if a value matches a certain string, and the input
I want to check if a certain key/value pair has been set. How do
If I have an array of ints, and I want to quickly check if
So I have acquired the element I want, but I want to check the
I have a certain check to be done and if the check satisfies, I
What Javascript function is used to check for a certain plugin? Such as for
In my asp.net mvc app I want to check if a certain url returns
I want to check users' subscribed dates for certain period. And send mail to
I need to check to see if the user selects a certain value in
i'm using setInterval to check if a p(html paragraph) has a certain text value.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.