Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and work.

aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

You have the vaccine, now let everyone know!
Teach Your Child To Read

BlueHost Web Hosting Black Friday

Bonsai Boy of New York Bonsai Trees and Accessories

DreamCloud The Comfortable Luxury Mattress Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

17,941 questions

24,112 answers

573 users

How to print numbers in scientific notation in C

1 Answer

0 votes
#include <stdio.h>

int main(void)
{
    float n1 = 250000000;
    float n2 = -250000000;
    double n3 = 123.897;
    double n4 = 0.0000016002;

    printf("n1 (%%f) - %f\n", n1);
    printf("n1 (%%E) - %E\n", n1);
    printf("n1 (%%.2e) - %.2e\n", n1);

    printf("n2 (%%f) - %f\n", n2);
    printf("n2 (%%E) - %E\n", n2);
    printf("n2 (%%.1e) - %.1e\n", n2);

    printf("n3 (%%f) - %f\n", n3);
    printf("n3 (%%E) - %E\n", n3);
    printf("n3 (%%.2e) - %.2e\n", n3);

    printf("n4 (%%f) - %f\n", n4);
    printf("n4 (%%E) - %E\n", n4);
    printf("n4 (%%.1e) - %.1e\n", n4);

    return 0;
}




/*
run

n1 (%f) - 250000000.000000
n1 (%E) - 2.500000E+008
n1 (%.2e) - 2.50e+008
n2 (%f) - -250000000.000000
n2 (%E) - -2.500000E+008
n2 (%.1e) - -2.5e+008
n3 (%f) - 123.897000
n3 (%E) - 1.238970E+002
n3 (%.2e) - 1.24e+002
n4 (%f) - 0.000002
n4 (%E) - 1.600200E-006
n4 (%.1e) - 1.6e-006

*/

 




answered May 2 by avibootz
...