Thread: Entering floating numbers

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    34

    Entering floating numbers

    Hi,

    I'm trying to write a little program that will help me calculate minority and majority carriers in semiconductors based on my input. The program should handle large numbers, typically around 10^12-10^17.

    However, I'm stuck on the very start:

    Code:
    #include <stdio.h>
    
    int main() {
    
    	double d=0;
    
    	scanf("%e", &d);
    	printf("%e\n", d);
    
    	return 0;
    
    }
    I'm sure something is wrong with this code, but what? For example, when I type in 15, it prints out 5.424145e-315.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Code:
    #include <stdio.h>
    
    int main() {
    
    double d=0;
    
    scanf("%le", &d);
    printf("%e\n", d);
    
    return 0;
    
    }
    %e is the same as %f which is for float. %le makes it a double (at least on gcc)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 11-11-2008, 05:32 AM
  2. Problem with floating point numbers
    By thetinman in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2005, 06:55 PM
  3. Floating point numbers in a binary file
    By frenchfry164 in forum C++ Programming
    Replies: 6
    Last Post: 07-31-2003, 10:04 AM
  4. Floating point numbers
    By noor_mirza in forum C++ Programming
    Replies: 3
    Last Post: 10-23-2002, 03:40 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM