Solved

maximum value in array

Posted on 2006-11-09
2
246 Views
Last Modified: 2010-04-15


I have a code that can return me the maximum value in a giving array (like below ). how can I change it to return me the maximum value for each row.
for example, I wan to the code return me like

the maximum value in row 1 is: 4
the maximum value in row 2 is: 8
the maximum value in row 3 is: 4


#include <stdio.h>
#include <stdlib.h>
#include <float.h>
                                 
int t [3][3]={  {3,3,4},
                {8,2,1},
                {3,3,4}
              };                    
                   

main (){
   
   int i,j, max;
   max=t[0][0];
   
   for (i=0; i<3 ; i++){
      for (j=0; j<3; j++){
        if (t[i][j]>max)
          max=t[i][j];
      }
   }

printf("max vaule is : %d\n",max );
system("pause");
return 0;

}
0
Comment
Question by:rmtogether
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
Comment Utility
Almost there, that should be

main (){
   
   int i,j, max;
   
   for (i=0; i<3 ; i++){
      max = 0;
      for (j=0; j<3; j++){
        if (t[i][j]>max) {
          max=t[i][j];
        }
      }
      printf("max vaule is : %d\n",max );
   }

system("pause");
return 0;

}
0
 

Author Comment

by:rmtogether
Comment Utility
thanks your are so fast....
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now