#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Question Fonction matriz in C++


    please help me!!!! with this program,it's urgent.

    it say:print the square root of each element of the matrix 7 * 7, use the sqrt function.
    #include<conio.h>
    #include<stdio.h>
    #include<math.h>
    #define F 7
    #define C 7
    void func_matriz(int mat[][7]);
    double sqrt(float mat[][7]);
    void imprimir(int mat[][7]);
    void suma(int mat[][7]);
    int main()
    {
    int mat[7][7];
    func_matriz(mat);
    imprimir(mat);

    getch();
    }
    void func_matriz(int mat[][7])
    {


    int i,j;


    for(i=0;i<F;i++)
    {
    for(j=0;j<C;j++)
    {
    if(i==j)
    mat[i][j]=0;
    else if(i+j==(7-1))
    mat[i][j]=0;
    else

    mat[i][j]=((i+0)+j);





    }
    }
    }
    void imprimir(int mat[][7])

    {

    int i=0,j=0;



    for(i=0;i<F;i++)

    {

    for(j=0;j<C;j++)

    {

    printf("\t %f",sqrt((double)(mat[i][j])));

    }

    printf("\n\n");

    }

    }
    please!! help me to compile a program, so that the square root of each element of this matrix will print
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    45
    Rep Power
    8
    Edit your code using CODE tags and indentations then ask again.

    Comments on this post

    • salem agrees
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0
    the 7th line
    double sqrt(float mat[][7]);
    is not needed because the square root function is included in "math.h"
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,158
    Rep Power
    2222
    These are the warnings that your program is throwing:
    C:TEST>gcc -Wall pepi1.c
    pepi1.c:9: warning: conflicting types for built-in function `sqrt'
    pepi1.c: In function `main':
    pepi1.c:20: warning: control reaches end of non-void function
    pepi1.c: In function `imprimir':
    pepi1.c:48: incompatible type for argument 1 of `sqrt'

    C:TEST>
    Of course, these line numbers won't do you any good, because I did some minor clean-up of your code by inserting empty lines between the functions and removing the over-abundant empty lines within the functions. Please pay attention to making your code readable. So you will need to read the warnings you get when you compile your program in order to see while lines are causing them.

    As it is, at fault is, as zaq12345 pointed out, your extraneous declaration of sqrt which is a redefinition that is incompatible with the function prototype in math.h . C++ allows you to overload functions by giving them different parameters, but C does not allow that; every function needs to have a unique name.

    Furthermore, when you do call sqrt, you are not calling it with a matrix but rather with an element from a matix, a double (actually, an int cast to a double). So why declare a different version of sqrt that takes a matrix? That makes no sense.

    Anyway, after correcting that, all it complains about is the missing return statement in main:
    C:TEST>gcc -Wall pepi1.c
    pepi1.c: In function `main':
    pepi1.c:20: warning: control reaches end of non-void function

    C:TEST>
    Never ignore warnings. Warnings are more important than error messages. Never ignore warnings.

IMN logo majestic logo threadwatch logo seochat tools logo