Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
August 19th, 2013, 01:31 AM
 pepi25
Registered User

Join Date: Aug 2013
Posts: 1
Time spent in forums: 14 m 46 sec
Reputation Power: 0
Fonction matriz in C++

it sayrint 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
August 19th, 2013, 04:25 AM
 DRK82
Contributing User

Join Date: Jun 2009
Posts: 45
Time spent in forums: 1 Day 11 h 48 m 59 sec
Reputation Power: 7
salem agrees!

#3
August 19th, 2013, 05:51 AM
 zaq12345
Registered User

Join Date: Aug 2013
Posts: 1
Time spent in forums: 11 m
Reputation Power: 0
the 7th line
double sqrt(float mat[][7]);
is not needed because the square root function is included in "math.h"

#4
August 19th, 2013, 03:06 PM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,890
Time spent in forums: 3 Months 1 Day 19 h 4 m 17 sec
Reputation Power: 2199
These are the warnings that your program is throwing:
Quote:
 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:
Quote:
 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.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Fonction matriz in C++