Multiplying Columns of Numbers in C Programming

Click For Summary
A user developed a C program to multiply a column of numbers and achieved correct results, but faced formatting issues with the output. The output displayed as 0.00005672, while the user desired it in scientific notation, such as 5.672E or D-5. Suggestions included utilizing format specifiers in the printf function, specifically recommending the 'e' format for scientific notation. The 'g' format was also mentioned as an alternative that automatically chooses the shorter representation between 'e' and 'f'. Users were encouraged to refer to documentation on format specifiers for further guidance.
Rajini
Messages
619
Reaction score
4
Hello all,

I wrote a C program to multiply a column of numbers (for eg., number will look like this 10.45618) with some constant...
after multiplication i get the correct value (i tested using calculator).
Now the output is 0.00005672 (i use %14.9lf) ..but i want them to display like this: 5.672E or D-5.
E stands for 10.
thanks for your help.
 
Technology news on Phys.org
Check the documentation on format specifiers for printf. There are a lot of useful options, it would be good to know what's possible and know where to look things up -- so go googling!

I think for your particular issue, you want 'e' or 'g' instead of 'f'; I don't remember which one.
 
It's e. g uses the shorter of the e vs. f formats.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 28 ·
Replies
28
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 30 ·
2
Replies
30
Views
6K
Replies
14
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 25 ·
Replies
25
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 19 ·
Replies
19
Views
2K