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

203
Views
cómo C calcula el tipo de datos int y float mezclado

[SOLUCIONADO]

Estoy aprendiendo C y encontré algunos problemas durante mi proceso de aprendizaje.

Cuando intento calcular un tipo de datos int y un tipo de datos flotante en una ecuación, terminé obteniendo 2 resultados diferentes. y estoy confundido porque lógicamente el resultado debería ser el mismo.

aquí está mi código versión 1 y versión 2. La diferencia radica en la variable z.

  • el primer caso: el valor de z es 1
  • el segundo caso: el valor de z es 0

Toda la entrada es 11

ACTUALIZAR 1

gracias a todos por sus comentarios y respuestas. pero todavía estoy confundido acerca de qué papel juega la variable p en el caso 1 y cómo podría llevar a que la variable z fuera 1 en lugar de 0.

Caso 1

 int main() { float a, fee, p; int x, y,z; scanf("%f", &a); fee = 0.6 * a; x = (int)(fee); y = (int)(2 * fee - 2 * x); p = fee * 10.0; z = (int)(p - 10 * x - 5 * y); printf("%f %d %d %d", fee, x, y, z); return 0; }

Caso 2

 int main() { float a, fee, p; int x, y,z; scanf("%f", &a); fee = 0.6 * a; x = (int)(fee); y = (int)(2 * fee - 2 * x); z = (int)(fee * 10.0 - 10 * x - 5 * y); printf("%f %d %d %d", fee, x, y, z); return 0; }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

1) z = (int)(p - 10 * x - 5 * y); FIIII // Float or Int 2) z = (int)(fee * 10.0 - 10 * x - 5 * y); // semicolon removed FDIIII // Float, Double or Int

Todos los cálculos en 1) se realizan con precisión float , en 2) con precisión double .

Sugerencia: siempre prefiera double cuando use valores de coma flotante.

over 4 years ago · Santiago Trujillo Report

0

si lanza un número de coma flotante menor que 1 como 0.9f a INT, se convertirá en cero.

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!