Answer to Question #259327 in C for Mr Z

Question #259327

1. Write a C program using an online C compiler that implements the following:-

• Declare a floating-point variable (of type float)

• Declare an integer variable (of type int)

• Prompt the user to enter a floating-point number.

• Read a number from the keyboard into your floating-point variable

• Using casting, write the contents of your floating-point variable into your integer variable • Display the value of your integer variable.


1
Expert's answer
2021-10-31T12:08:43-0400
#include <stdio.h>

int main()
{
    float f;
    int i;

    printf("Enter float value: ");
    if(scanf("%f", &f) != 1)
    {
        printf("Bad input\n");
        return 1;
    }

    i = (int) f;

    printf("Int value is: %d\n", i);
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS