Number in C++
Numbers in C++ expressions are interpreted as decimal numbers, unless you specify them in another manner. To specify a hexadecimal integer, add 0x before the number. To specify an octal integer, add 0 (zero) before the number.
The default debugger radix does not affect how you enter C++ expressions. You cannot directly enter a binary number (except by nesting a MASM expression within the C++ expression).
// Example to show various number in C++
#include <iostream>
using namespace std;
int main ()
{
// number definition:
short s;
int i;
long l;
float f;
double d;
// number assignments;
s = 11;
i = 1111;
l = 1111111;
f = 111.11;
d = 11111.11;
// number printing;
cout << "short s :" << s << endl;
cout << "int i :" << i << endl;
cout << "long l :" << l << endl;
cout << "float f :" << f << endl;
cout << "double d :" << d << endl;
return 0;
}
// Program to Generate Random Number in C++
#include<iostream>
#include<cstdlib>
using namespace std;
main()
{
int n, max, num, c;
cout << "Enter the number of random numbers you want ";
cin >> n;
cout << "Enter the maximum value of random number ";
cin >> max;
cout << "random numbers from 0 to " << max
<< " are :-" << endl;
for ( c = 1 ; c <= n ; c++ )
{
num = random(max);
cout << num << endl;
}
return 0;
}