Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
Complex numbers through scanf in C

I have problem with following fragment of code:

int main()
{
    int n = 3;

    complex_t t[3];
    for(int i = 0; i < n; i++)
    {
        double x, y;
        printf("Enter complex number: ");
        scanf("%f %f", &x, &y);
        t[i].re = x;
        t[i].im = y;
    }
}

When I am trying to pass x, and y to the program, it doesn't change value, and is 0.00000. Can you help me?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You've declared x and y as doubles, but then went on to use the format specifier for floats (%f). So the end result is reading them in as if they were regular floats, then jamming the result into a double leaving you with unexpected values when trying to actually use them.

You need to use the format specifier specifically for doubles (%lf) here.

scanf("%lf %lf", &x, &y);

See format string specifications for more information about different format specifiers.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda