Given a positive decimal number, find the simple exponential notation (x = a·10^b) of the given number.

Examples:

Input : 100.0 Output : 1E2 Explanation: The exponential notation of 100.0 is 1E2. Input :19 Output :1.9E1 Explanation: The exponential notation of 16 is 1.6E1.

**Approach:**

The simplest way is to find the position of the first non zero digit and the position of the dot. The difference between that positions is the value of b (if the value is positive you should also decrease it by one).

Below is the implementation of the above approach:

`// C++ code to find the exponential notation ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// function to calculate the exponential ` `// notation ` `void` `FindExponent(` `char` `s[], ` `int` `n) ` `{ ` ` ` `int` `i, j, b, c; ` ` ` `for` `(i = 0; s[i] == ` `'0'` `|| s[i] == ` `'.'` `; i++) ` ` ` `; ` ` ` `for` `(j = n - 1; s[j] == ` `'0'` `|| s[j] == ` `'.'` `; j--) ` ` ` `; ` ` ` ` ` `c = find(s, s + n, ` `'.'` `) - s; ` ` ` `putchar` `(s[i]); ` ` ` ` ` `if` `(i != j) ` ` ` `putchar` `(` `'.'` `); ` ` ` ` ` `for` `(` `int` `k = i + 1; k <= j; k++) ` ` ` `if` `(s[k] != ` `'.'` `) ` ` ` `putchar` `(s[k]); ` ` ` `if` `(i < c) ` ` ` `b = c - i - 1; ` ` ` `else` ` ` `b = c - i; ` ` ` `if` `(b) ` ` ` `printf` `(` `"E%d"` `, b); ` `} ` ` ` `// main function ` `int` `main() ` `{ ` ` ` `char` `s[] = ` `"100"` `; ` ` ` `int` `n = ` `strlen` `(s); ` ` ` `FindExponent(s, n); ` `} ` |

Output:

1E2

## Recommended Posts:

- Prime Numbers
- k-th number in the Odd-Even sequence
- Given N and Standard Deviation, find N elements
- Given a large number, check if a subsequence of digits is divisible by 8
- Find all possible coordinates of parallelogram
- Total no of 1's in numbers
- Check if a number is power of k using base changing method
- Check if a number N starts with 1 in b-base
- Operators in C / C++
- Juggler Sequence
- Convert from any base to decimal and vice versa
- Power Set
- Sum of width (max and min diff) of all Subsequences
- Ways of selecting men and women from a group to make a team
- Find subsequences with maximum Bitwise AND and Bitwise OR

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.