Thread: Finding lenght on elements

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    Kansas City
    Posts
    76

    Finding lenght on elements

    I have a vector of colors, its elements are "red", "blue", "black" ...
    how can I find which element has the longest name ?

    I been playing with this for fwe hours and still can't figure this out.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    How about this to start off with?
    Code:
    T max = a[0];
    
    for ( i = 1; i < n; i++ ) {
      if ( a[i] > max )
        max = a[i];
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help in Matrix Addition & finding Inverse of a Matrix
    By ssatyan.129 in forum C Programming
    Replies: 6
    Last Post: 05-15-2009, 02:48 PM
  2. using realloc for a dynamically growing array
    By broli86 in forum C Programming
    Replies: 10
    Last Post: 06-27-2008, 05:37 AM
  3. way to check 3 elements of array and set 4th
    By Syneris in forum C++ Programming
    Replies: 3
    Last Post: 01-09-2006, 11:30 AM
  4. MFC :: Finding Child Window of a CWnd* Object?
    By SyntaxBubble in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2003, 09:06 AM
  5. Finding elements in an array
    By MethodMan in forum C Programming
    Replies: 3
    Last Post: 04-05-2003, 02:20 PM