How can I print the fifth part of a real number?

Asked

Viewed 3,142 times

2

How could I print the fifth (index 4 from the dot) part of a real number without using libraries or a "complex" code for initial chapters.

  • Make a program that reads a real number, and print the fifth part of that number.
  • The fifth part would not be 1/5 of the number?

  • I believe it’s the 5 element, these are the only information passed

2 answers

3


#include <stdio.h>
#include <stdlib.h>

int main (void) {
   double entrada, quintaParte;
   printf ("Digite um numero: \n");

   scanf ("%lf", &entrada);

   quintaParte = entrada * 1/5;
   printf ("A quinta parte de %lf eh: \n %lf\n",  entrada, quintaParte);

   return 0;
}

inserir a descrição da imagem aqui

-2

inserir a descrição da imagem aquiIn Python it would be like this:

n = float(input('Digite um número: '))

q = n * (1/5)

print('A quinta parte de {:.2f} é {:.2f}'.format(n, q))

Thanks for the opportunity.

  • Please add more details to expand your response, such as a working code or documentation quotes.

  • The question refers c and not python

Browser other questions tagged

You are not signed in. Login or sign up in order to post.