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;
}

Recommended Answers

All 2 Replies

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

Solved :)

What just I did is this :-

    int main() {
    int n;
    scanf("%d",&n);
    printf("%.5 ", 1./n);
    return 0;
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.