×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

max value in array columns

max value in array columns

max value in array columns

(OP)
I could not figure out how to write a function that counts elements greater than given max value in columns of a matrix separately.

Can somone help me, pls!
I tried:

int count = 0;
float max = 1.5;
for ( i = 0; i < rows; i++)
for ( j = 0; j < cols; j++)
{
if ( matrix[i][j] > max)
count += 1;
}

Above count all the values greater than max but how to report the separately?

Tips/advice would be highly appreciated.

kjb

RE: max value in array columns

Hi Kjb,

   What exactly you want to be reported ?
   Do you want the array element to be printed ?
   If so try the below code.

int count = 0;
float max = 1.5;
for ( i = 0; i < rows; i++)
for ( j = 0; j < cols; j++)
{
if ( matrix[j] > max)
{
count += 1;
printf(" The maxtrix[%d,%d] value %d is greater than %f\n And count is %d\n, i,j,max,count);
}
}

printf("No of Elements greater than %f is %d \n", max, count);

Cheers,
Baskar.


Baskar
baskar52@hotmail.com
http://www.geocities.com/baskar52
 

RE: max value in array columns

(OP)
Thanks Basking

Actually I need to find the count of elements greater than
a given value in 'each' column. In case of an array of 3 columns the return should be like:
2 6 4

Regards

kjb

RE: max value in array columns

I hope the follwoing code helps you.

int count;
float max = 1.5;
for ( j = 0; j < cols; j++)
{
 count = 0;
 for ( i = 0; i < rows; i++)
 {
   if ( matrix[j] > max)
   {
    count += 1;
    printf(" The maxtrix[%d,%d] value %d is greater than %f\n And count is %d\n, i,j,max,count);
   }
  }
  printf("No of Elements greater than %f in column %d is %d \n", max, j+1, count);
}
}

cheers,
Baskar

Baskar
baskar52@hotmail.com
http://www.geocities.com/baskar52
 

RE: max value in array columns

(OP)
Many thanks Basking

The function you wrote worked like magic!

Have a good day!

kjb

RE: max value in array columns

Hello all,

It seems to me you need a count for each column if I have followed this LONG thread correctly. So something like this...

int count[cols];
memset(count, 0, sizeof(int) * cols);

float max = 1.5;
for ( r = 0; r < rows; r++)
for ( j = 0; j < cols; j++)
{
if ( matrix[r][j] > max)
count[j]++;
}

Good luck
-pete

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close