Site icon Bytefreaks.net

C: Read a floating number that might be in the format of scientific notation

Advertisements

This code will read a floating number that might be in the format of scientific notation from the keyboard.
Then it will print out the number with the scientific notation and without it.


#include <stdio.h>
#include <stdlib.h>

int main() {
  printf("This code will read a floating number that might be in the format of scientific notation from the keyboard.\nThen it will print it out with the scientific notation and without\n");
  double input;
  printf("Enter a number in scientific notation. (e.g. -4e-5 or -4.00e-5 or -4.00e-05 etc.)\n");
  scanf("%lf", &input);
  printf("With scientific notation '%e'\n", input);
  printf("Without scientific notation '%lf'\n", input);
  return 0;
}

Examples

This code will read a floating number that might be in the format of scientific notation from the keyboard.
Then it will print it out with the scientific notation and without
Enter a number in scientific notation. (e.g. -4e-5 or -4.00e-5 or -4.00e-05 etc.)
4.5e-10
With scientific notation '4.500000e-10'
Without scientific notation '0.000000'
This code will read a floating number that might be in the format of scientific notation from the keyboard.
Then it will print it out with the scientific notation and without
Enter a number in scientific notation. (e.g. -4e-5 or -4.00e-5 or -4.00e-05 etc.)
4.5e-3
With scientific notation '4.500000e-03'
Without scientific notation '0.004500'

This post is also available in: Αγγλικα

Exit mobile version