Jump to content

Número real mostrando parte inteira e fraccionária.


Gurzi
 Share

Go to solution Solved by deathseeker25,

Recommended Posts

Um Utilizador Introduz um numero real e o programa deve ser capaz de mostrar a parte inteira e a parte decimal.

#include <stdio.h>

main()
{  	
float num;
   	
printf("Introduza um numero com parte decimal");
   	scanf("%f", &num);
   	printf("Parte Inteira : %d",(int) num);
   	printf("Parte Decimal : %f", num - ((int)num));
}

acontece que quando executo a parte decimal vai me dar por exemplo se num = 12,85 a parte decimal dá 0.850000 querendo eu apenas que mostre 0,85 retirando os 0.

Link to comment
Share on other sites

exacto.

Por exemplo:

#include <stdio.h>

main()
{
  float num;
  printf("Introduza um numero com parte decimal");
  scanf("%f", &num);
  printf("Parte Inteira : %d",(int) num);
  printf("Parte Decimal : %.2f", num - ((int)num));
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.