Answers for "c++ round function"

C++
0

c++ round to int

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int x = 15;
    double result;
    result = round(x);
    cout << "round(" << x << ") = " << result << endl;

    return 0;
}
Posted by: Guest on June-02-2020
0

round c++

#include<bits/stdc++.h>

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);

	int T; cin >> T;
	for (int case_num = 1; case_num <= T; case_num ++) {

		int64_t L, R; cin >> L >> R; R++;
		bool parity = 0;
		int64_t coeff = 1;
		int64_t ans = 0;
		while (L < R) {
			assert(1 <= L && L < R);
			auto is_good = [&](int64_t v) {
				assert(v > 0);
				bool d = v % 2;
				while (v > 0) {
					if (v % 2 != d) return false;
					d = !d;
					v /= 10;
				}
				return d == 0;
			};
			while (L < R && L % 10 != 0) {
				if (is_good(L)) {
					ans += coeff;
				}
				L++;
			}
			while (L < R && R % 10 != 0) {
				--R;
				if (is_good(R)) {
					ans += coeff;
				}
			}

			if (L == R) break;
			assert(L % 10 == 0 && R % 10 == 0);
			assert(L >= 10);

			L /= 10;
sorry for the error
Posted by: Guest on June-05-2021
0

c++ round function

double round(double x);
float round(float x);
long double round(long double x);
double round(T x); // For integral type
Posted by: Guest on July-07-2020

Browse Popular Code Answers by Language