OpenJudge 06:Floating-point number rounding to zero

Description

Enter a single-precision floating-point number, rounded toward zero to an integer.

Explanation: Rounding to zero means that positive numbers are rounded down and negative numbers are rounded up.
Hint: You can use casts to achieve this.

Input

A single-precision floating-point number.

Output

An integer, that is, the result of rounding toward zero to an integer.

Input sample

2.3

Output sample

2

Answer

C++
1
2
3
4
5
6
7
8
9
#include<iostream>
using namespace std;
int main()
{
float a;
cin>>a;
cout<<int(a)<<endl;
return 0;
}

Result

Used memory: 200kB
Run time: 10ms
Language:G++
Submit time:2019-03-24 09:48:35

http://noi.openjudge.cn/ch0102/06/

OpenJudge 06:Floating-point number rounding to zero

https://blog.tsinbei.com/en/archives/540/

Author
Hsukqi Lee
Posted on

2022-07-03

Edited on

2022-07-28

Licensed under

CC BY-NC-ND 4.0

# Programing  Cpp  OpenJudge  NOI  NOIP

Comments

Name
Mail
Site
None yet