basic doubt

This is a discussion on basic doubt within the C Programming forums, part of the General Programming Boards category; code: #include<stdio.h> main() float i; i=16.0/9; printf("%d",i); } i m getting 0 as output instead of 1. why?...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    2

    Post basic doubt

    code:

    #include<stdio.h>
    main()
    float i;
    i=16.0/9;
    printf("%d",i);
    }


    i m getting 0 as output instead of 1. why?

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    division as double, and that's not how you print a float (&#37;d is a signed integer and %f is a float), See http://www.cplusplus.com/reference/c...io/printf.html

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        float i;
        i = 16.0f / 9.0f;
        printf("%f", i);
    
        return 0;
    }
    Quote Originally Posted by iMalc
    It's "Question" not "Doubt".
    "Doubt" is a statement about yourself only.
    A "Question" is something you ask other people.

    Please learn the difference, and tell everyone else you know to learn it too!
    Last edited by zacs7; 06-20-2007 at 03:36 AM. Reason: Miss wording pointed out by vart

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    division was OK... it was even performed as double and then shortened to float...

    printf format IS really a problem...

    and also missing code tags
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function calling: basic doubt
    By doubty in forum C Programming
    Replies: 10
    Last Post: 06-23-2009, 02:31 AM
  2. basic doubt
    By vikranth in forum C Programming
    Replies: 7
    Last Post: 10-30-2007, 11:21 AM
  3. [B]a basic doubt !![/B]
    By samirself in forum C Programming
    Replies: 6
    Last Post: 04-30-2005, 01:39 PM
  4. basic doubt in pointer concept
    By sanju in forum C Programming
    Replies: 1
    Last Post: 10-24-2002, 11:35 PM

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