0
Float to nearest int
How can i change a float result to nearest integer? Like 45.49 -> 45 or 45.51 -> 46.
5 Respuestas
+ 4
Francesco Rossi
Use the `round()` function from the math library to round a float to the nearest integer.
Otherhand,
If you're having trouble in code, share your code and describe what error message you're receiving.
+ 1
Francesco Rossi
You need to complete this course.
https://www.sololearn.com/learn/courses/c-intermediate
https://www.sololearn.com/learn/courses/c-introduction
Note that..`stdio.h` and `round()` are not the same,they serve different purposes in C programming.
The `stdio.h` is a library in C, which provides functions for input and output operations, such as reading and writing to the console.
It includes functions like `printf()` and `scanf()`.
Other hand, the `round()` is a function ,round function is a part of the `math.h` library in C.
It is used for rounding floating-point numbers to the nearest integer & This function takes a floating-point number as input and returns the rounded integer value.
0
How if i have to use a stdio.h library only? It is for an exercise here
0
#include <stdio.h>
#include <math.h>
int main() {
float number = 45.49;
int roundedNumber = round(number);
printf("original number: %.2f\n", number);
printf("rounded number: %d\n", roundedNumber);
return 0;
}
0
Thank you so much guys, really kind, someone could tell me how code "halloween candy" exercise in code coach? It is an Easy task but i can't do it