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.
#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;
}
Comments
Leave a comment