Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!