Thread: :)

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    6

    Question :)

    hi! i have a problem here because the method doesn't work properly, the point of the code is to tell the minimun value in the given matrix "m", it's supposed to take the first value of the matrix store it in min_ and then compare it to every value of the matrix, if the value stored in min_ is bigger than the current value in the loop then it's stored as the new min_ and at the end it's supposed to print that minimum... i'd really appreciate the help! thanks!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define SIZE 3
    
    
    void minimum (int mat[SIZE][SIZE]){
        int r,c;
        int min_;
        printf("\n");
        min_=mat[0][0];
        for (r=0;r<SIZE;r++){
            for (c=0;c<SIZE;c++){
                if (min_>=mat[r][c]){
                min_=mat[r][c];
                }
            }
        }
        printf("The minimum value of the matrix is: %i\n", min_);
       
    
    
    }//minimum
    
    
    
    int main()
    {
        
        printf("HW #3 :) .\n\n");
        int m[SIZE][SIZE]={{1,2,3},
                           {4,5,6},
                           {7,8,9}};
    
    
        
        minumum(m);
        
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    You need to work on your thread titles. You should describe briefly what the problem is, e.g. "Can't find minimum of matrix". Emoticons don't convey the problem, and smiley ones don't convey any problem at all.

    Also, your description says nothing about the actual problem. "It doesn't work properly" is a pretty useless description. What doesn't work about it? Does it compile? You should be compiling with maximum warning levels, and fixing all errors and warnings. If it doesn't compile cleanly, what error messages do you get (copy-paste them exactly with line numbers). If it compiles, what happens when you run it? Does it print error messages? Does it crash? Does it produce no output, or incorrect output? Give a sample input, the output your program produces, and the correct output it should produce.

    What makes you say it doesn't work properly? Have you tested it? Does that code even compile?
    Last edited by anduril462; 06-16-2013 at 07:02 PM.

  3. #3
    Registered User
    Join Date
    May 2013
    Posts
    6
    haha yeah i suppose you're right, sorry for that, i'll work on it... the thing is that the program runs correctly but produces no output at all, as i said it should give the minimum value of the whole matrix just as the printf says, anyway just by looking at it by myself i figured it out... i misspelled the method in "main" that's why it didn't work... but now it's all fixed. thanks anyway.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by spacemonkey View Post
    haha yeah i suppose you're right, sorry for that, i'll work on it... the thing is that the program runs correctly but produces no output at all, as i said it should give the minimum value of the whole matrix just as the printf says, anyway just by looking at it by myself i figured it out... i misspelled the method in "main" that's why it didn't work... but now it's all fixed. thanks anyway.
    For some strange reason I have doubts that misspelling the name of the function as you did would result in a program that compiled without errors and would be executable.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User dpwisler3's Avatar
    Join Date
    Jun 2013
    Location
    Anderson, South Carolina, United States
    Posts
    1
    Hi. I compiled and ran your code. It ran fine once I changed the name of the function call to "minimum".

  6. #6
    Registered User
    Join Date
    May 2013
    Posts
    6
    the thing is that this is just a part of the whole code i was working on, i just cut/paste the part that you can see, so when i ran the program everytime all the other functions were working allright but the output of this very funtion didn't appear so that's why i coulndn't find the problem. but i tried to run the code again only using the part that i posted here and i had an error that told me that i misspelled the funtion in main, so yeah your hunch was right

Popular pages Recent additions subscribe to a feed