Home » C++ programming language

llround() function with example in C++

C++ llround() function: Here, we are going to learn about the llround() function with example of cmath header in C++ programming language.
Submitted by IncludeHelp, on April 27, 2019

C++ llround() function

llround() function is a library function of cmath header, it is used to round the given value and casts to a long long integer, it accepts a number and returns the integer (long long int) value that is nearest to the number (with halfway cases).

Syntax of llround() function:

    llround(x);

Parameter(s): x – is the number to round nearest to zero with halfway cases.

Return value: long long int – it returns long long int type value that is the rounded value of the number x.

Example:

    Input:
    float x = 2.3;    
    Function call:
    llround(x);    
    Output:
    2

    Input:
    float x = 2.8;
    Function call:
    llround(x);    
    Output:
    3

C++ code to demonstrate the example of llround() function

// C++ code to demonstrate the example of 
// llround() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    float x;
    
    x = 15.3;
    cout<<"llround("<<x<<"): "<<llround(x)<<endl;

    x = 15.5;
    cout<<"llround("<<x<<"): "<<llround(x)<<endl;

    x = 15.8;
    cout<<"llround("<<x<<"): "<<llround(x)<<endl;

    x = -15.3;
    cout<<"llround("<<x<<"): "<<llround(x)<<endl;

    x = -15.5;
    cout<<"llround("<<x<<"): "<<llround(x)<<endl;

    x = -15.8;
    cout<<"llround("<<x<<"): "<<llround(x)<<endl;    

    return 0;
}

Output

llround(15.3): 15
llround(15.5): 16
llround(15.8): 16
llround(-15.3): -15
llround(-15.5): -16
llround(-15.8): -16





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.