I'm using the following code to get the output up to 5 decimal characters of any number input by user when divided by 1, I have to typecast it with (float)
.
Can any one tell me how this can be done without typecasting or using float constant?
int main() {
int n;
scanf("%d",&n);
printf("%.5 ", 1/(float)n);
return 0;
}
Taking your question strictly literally, you could do:
int main() {
float n;
scanf("%f",&n);
printf("%.5f", 1/n);
return 0;
}
In this code, there is no float literal and no (float)
cast.
从技术上讲,这应该做到:
printf("%.5f ", 1/pow(n,1));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.