Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
Division in C language

Hello fellas hope you all doing well i am kinda newbie in C language, I just need to ask a basic question that is that when i divide numbers in C like this:

#include<stdio.h>
main()
{
   float a = 15/4;
   printf("%.2f", a);
}

the division happens but the answer comes in a form like 3.00(which is not correct it did'nt count the remainders) But when i program it like this:

#include<stdio.h>
main()
{
   float a = 15;
   float b = 4;
   float res = a/b;
   printf("%.2f", res);
}

this method gives me the correct answer. So i want to ask the reason behind the difference b/w these two programs why doesn't the first method works and why the second method working?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

In this expression

15/4

the both operands have integer types (more precisely the type int). So the integer arithmetic is performed.

If at least one operand had a floating point type (float or double) as for example

15/4.0

or

15/4.0f

then the result will be a floating point number (in the first expression of the type double and in the second expression of the type float)

And in this expression

a/b

the both operands have floating point types (the type float). So the result is also a floating point number.

over 4 years ago · Santiago Trujillo Relatório

0

When you state your varable to float you automatically casting the values he get from the equation. For example: Float a = 2/4 it's like writing float a = float(equation). Take care, Ori

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda