-4
#include <stdio.h>
#include <math.h>

int main ()  {

    float a, b, c, s, ar;
    s=((a+b+c)/2);

    printf("Ingrese los  lado del triangulo");

    scanf("%f%f%f",&a,&b,&c);


    ar=(sqrt(s*(s-a)*(s-b)*(s-c)));

    printf("el perimetro es %f",ar);

    return 0;
}

I do not understand why when compiling me throw this error

tmp/ccs6PFsP.o: En la función main':
ejercicio 34.c:(.text+0x87): referencia asqrt' sin definir collect2: error: ld returned 1 exit status

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • 5
    You should compile with `-lm` flag to link against the `math` library. – Eugene Sh. Jun 22 '17 at 16:06
  • 1
    You also can't compute `s` before you have the values for `a`, `b`, and `c`. – Fred Larson Jun 22 '17 at 16:08
  • Ya que estas aprendiendo, trata de usar un estilo mas agradable a la vista. Usa espacios entre operadores, no dejes lineas en blanco solo por dejarlas, etc. Es una parte esencial de ser bueno, tener un buen estilo. Principalmente, porque se lee mas de lo que se escribe codigo. Oh, and never use spaces in file names, that's a potential nightmare when you try to do something with the files, in a shell. – Iharob Al Asimi Jun 22 '17 at 16:09
  • 1
    You may find it useful to compile in an English or C environment when posting your error messages here: something like `LANG=C gcc -o foo foo.c -Wall -Wextra` for example. That enables more people to offer help. – Toby Speight Jun 22 '17 at 16:14
  • 1
    Aside: You may find [Stack Overflow en español](https://es.stackoverflow.com) easier for you to understand - this site is meant to be English-only. – iRove Jun 22 '17 at 16:22

2 Answers2

2

To use the math library in C, pass the lm flag to the compiler:

gcc main.c -lm

Then your program will compile and link against the math library.

Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
1

As pointed out, to use -lm flag while compiling, although it seems the logic is not correct.

In order to make your program work, you should insert this statement

s=((a+b+c)/2);

after the scanf statement.

In your code, you are calculating the sum of a, b and c before even reading the values from terminal.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Darpan
  • 113
  • 7