i am begginer to C ,I am trying to create tow files f1.c to input numbers and a second one f2.c to calculate their square and call them from main.c and finally a header.h to collect them f1.c code :
#include <stdio.h>
#include <math.h>
#include "header.h"
void f1()
{
int n,monTableau[n],i;
printf("Enter la taiile de vecteur n = : ");
scanf("%d", &n);
for (i=0;i<n;i++){
printf("\n Enter an la valeur i : ");
scanf("%d", &monTableau[i]);
};
}
f2.c code :
#include <stdio.h>
#include <math.h>
#include "header.h"
void f2()
{
int n,i,monTableau[n];
float resultas[n];
for (i=0;i<n;i++){
resultas[i] = sqrt( monTableau[i] );
};
for (i=0;i<n;i++){
printf("\n la racine de i eme valeur de tableau : %f ",resultas[i]);
};
}
main.c code :
#include <stdio.h>
#include "header.h"
void main()
{
f1();
f2();
}
header.h code :
void f1();
void f2();
and the error I got when i compile it in the terminal using this command:
gcc f1.c f2.c main.c -o final
is
/usr/bin/ld: /tmp/cc4kRvmX.o: in function `f2':
f2.c:(.text+0x1a8): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status