C ++ llround () - C ++ standaardbibliotheek

De functie llround () in C ++ rondt de gehele waarde af die het dichtst bij het argument ligt, waarbij hoofdletters halverwege worden afgerond vanaf nul.

De functie llround () in C ++ rondt de gehele waarde af die het dichtst bij het argument ligt, waarbij hoofdletters halverwege worden afgerond vanaf nul. De geretourneerde waarde is van het type long long int. Het is vergelijkbaar met de functie lround (), maar retourneert een lange lange int terwijl lround een lange int retourneert.

llround () prototype (vanaf C ++ 11-standaard)

lang lang int llround (dubbele x); long long int llround (float x); lange lange int llround (lange dubbele x); lang lang int llround (T x); // Voor integraal type

De functie llround () accepteert één argument en retourneert een waarde van het type long long int. Deze functie is gedefinieerd in het header-bestand.

llround () Parameters

De functie llround () heeft een enkele argumentwaarde nodig om af te ronden.

llround () Retourwaarde

De functie llround () retourneert de integrale waarde die het dichtst bij x ligt, waarbij hoofdletters halverwege zijn afgerond vanaf nul. De geretourneerde waarde is van het type long long int.

Voorbeeld 1: Hoe werkt llround () in C ++?

 #include #include using namespace std; int main() ( long long int result; double x = 11.16; result = llround(x); cout << "llround(" << x << ") = " << result << endl; x = 13.87; result = llround(x); cout << "llround(" << x << ") = " << result << endl; x = 50.5; result = llround(x); cout << "llround(" << x << ") = " << result << endl; x = -11.16; result = llround(x); cout << "llround(" << x << ") = " << result << endl; x = -13.87; result = llround(x); cout << "llround(" << x << ") = " << result << endl; x = -50.5; result = llround(x); cout << "llround(" << x << ") = " << result << endl; return 0; )

Wanneer u het programma uitvoert, is de uitvoer:

 llround (11.16) = 11 llround (13.87) = 14 llround (50.5) = 51 llround (-11.16) = -11 llround (-13.87) = -14 llround (-50.5) = -51

Voorbeeld 2: functie llround () voor integrale typen

 #include #include using namespace std; int main() ( int x = 15; long long int result; result = llround(x); cout << "llround(" << x << ") = " << result << endl; return 0; ) 

Wanneer u het programma uitvoert, is de uitvoer:

 llround (15) = 15 

Voor integrale waarden retourneert het toepassen van de functie llround dezelfde waarde als de invoer. Het wordt dus in de praktijk niet vaak gebruikt voor integrale waarden.

Interessante artikelen...