% hw012.m
% John Burkardt
% Rewrite (positive) X in scientific notation M * 10^E.
%
%  X is the number to analyze.
%  M is the mantissa, 1 <= M < 10.
%  E is the exponent, an integer.
%
x = input ( 'Enter a positive number X: ' );

if ( x <= 0.0 )
  error ( '  X must be positive!' );
end

m = x;
e = 0;

while ( 10.0 <= m )
  m = m / 10;
  e = e + 1;
end

while ( m < 1.0 )
  m = m * 10;
  e = e - 1;
end

fprintf ( '  X = %g = %g * 10^%d = %g\n', x, m, e, m * 10^e );

