August 19th, 2013, 01:31 AM

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==(71))
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
August 19th, 2013, 04:25 AM

Edit your code using CODE tags and indentations then ask again.
Comments on this post
August 19th, 2013, 05:51 AM

the 7th line
double sqrt(float mat[][7]);
is not needed because the square root function is included in "math.h"
August 19th, 2013, 03:06 PM

These are the warnings that your program is throwing:
C:TEST>gcc Wall pepi1.c
pepi1.c:9: warning: conflicting types for builtin function `sqrt'
pepi1.c: In function `main':
pepi1.c:20: warning: control reaches end of nonvoid 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 cleanup of your code by inserting empty lines between the functions and removing the overabundant 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 nonvoid function
C:TEST>
Never ignore warnings. Warnings are more important than error messages. Never ignore warnings.