Array Manupilation

Hi,

I have an interger array of size n. How can i write code such that

1. I get a 1 if ALL elements of the array are less than a certain number
2. I get a 0 if ANY element of the array is bigger than a certain number

This can be in functions or otherwise...[to have them both in a single function would be fantastic:)]

I thought abt it a lot but can`t think how to do it. Any help will be appreciated.

Thx in advance
Renegade007

Comments

  • : Hi,
    :
    : I have an interger array of size n. How can i write code such that
    :
    : 1. I get a 1 if ALL elements of the array are less than a certain
    : number
    : 2. I get a 0 if ANY element of the array is bigger than a certain
    : number
    :
    : This can be in functions or otherwise...[to have them both in a
    : single function would be fantastic:)]
    :
    : I thought abt it a lot but can`t think how to do it. Any help will
    : be appreciated.
    :
    : Thx in advance
    : Renegade007
    :
    This code frag should return 0 if any element is greater than a certain number, -1 if any element is equal to a certain number (a case you did not mention) and 1 if all the elements are less than the certain number. It's untested. Sorry.

    [code]
    for(i = 0 ; i < n ; i++) {
    if (a[i] > certainnum)
    return 0 ;
    if (a[i] == certainnum)
    return -1 ;
    }
    // we can only get to here if all elements are < certainnum
    return 1 ;
    [/code]
  • [code][code][/code][/code]: Hi,
    :
    : I have an interger array of size n. How can i write code such that
    :
    : 1. I get a 1 if ALL elements of the array are less than a certain
    : number
    : 2. I get a 0 if ANY element of the array is bigger than a certain
    : number
    :
    : This can be in functions or otherwise...[to have them both in a
    : single function would be fantastic:)]
    :
    : I thought abt it a lot but can`t think how to do it. Any help will
    : be appreciated.
    :
    : Thx in advance
    : Renegade007
    :

    hai,the code you requested for the programme is in the attachment,check it out,this code is working......

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories