What results in this output

This is a discussion on What results in this output within the C Programming forums, part of the General Programming Boards category; Code: * Ex.c: Outputs the nearest integer of the input number */ #include <stdio.h> int main(){ float in; int out; ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    4

    What results in this output

    Code:
    * Ex.c: Outputs the nearest integer of the input number */
    #include <stdio.h>
    
    int main(){
          
            float in;
            int out;
    
    	printf("Enter a real number: ");
    	
    	scanf("%f", &in);
    	out = (int)(in + 0.5);
    	printf("%f rounded == %d", out);
    
    	return 0;
    }
    The above program is intended to output the nearest integer of the input real number.I did not include the in variable to test what it will put out , I was expecting 23.00000..... something like that as I did input 23.25 But the out put was

    D:\C++\TIC\Chap02>Ex
    Enter a real number: 23.25
    0.000000 rounded == 1102708736
    Why am I not getting 23.000000 something?
    What makes this output ,when an floating point format specifier is used to output an integer

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Code:
    printf("%f rounded == %d", out);
    You're missing a parameter here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Switch statement and returning the correct output
    By slowcoder in forum C Programming
    Replies: 6
    Last Post: 09-28-2006, 05:00 PM
  2. Same seed for srand yields different results
    By codegirl in forum C++ Programming
    Replies: 3
    Last Post: 06-23-2003, 03:39 PM
  3. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  4. Control different DA output value!
    By Hunterhunter in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-13-2003, 12:11 PM
  5. show output from file
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 12-28-2001, 07:37 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21