1

I am doing following code to get the output upto 5 decimal characters of any number inputted by user when divided by 1, I have to use 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;
}

Edited by cse.avinash

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by cse.avinash
0

Try to declare a float variable; assign the (1/n) value to the float variable and print the
value.

Edited by phani1092

0

Solved :)

What just I did is this :-

    int main() {
    int n;
    scanf("%d",&n);
    printf("%.5 ", 1./n);
    return 0;
    }

Edited by cse.avinash: I forgot to insert the code and i posted

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.