xxxxxxxxxx
unsigned int number_of_digits = 0;
do {
++number_of_digits;
n /= base;
} while (n);
xxxxxxxxxx
ex: input = 2424, output = 4
static int intlen(int n)
{
if (n == 0) return 1;
else if (n < 0) return 2 + static_cast<std::size_t>(std::log10(-n));
else if (n > 0) return 1 + static_cast<std::size_t>(std::log10(n));
}
xxxxxxxxxx
#include <iostream>
using namespace std;
int main(){
cout << "Size of char: " << sizeof(char) << " byte" << endl;
cout << "Size of int: " << sizeof(int) << " bytes" << endl;
cout << "Size of float: " << sizeof(float) << " bytes" << endl;
cout << "Size of double: " << sizeof(double) << " bytes" << endl;
return 0;
}