What is a NaN ?

This is a discussion on What is a NaN ? within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> #include<conio.h> #include<math.h> main() { float a,b,c,d,k,x,y; clrscr(); printf("Enetr the values of a,b,c=>"); scanf("%f %f %f",&a,&b,&c); d=((b*b)-(4*a*c)); k=sqrt(d); x= ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    1

    What is a NaN ?

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    
    main()
    {
    float a,b,c,d,k,x,y;
    clrscr();
    printf("Enetr the values of a,b,c=>");
    scanf("%f %f %f",&a,&b,&c);
    d=((b*b)-(4*a*c));
    k=sqrt(d);
    x= (-b+k)/(2*a);
    y= (-b-k)/(2*a);
    printf("The quadratic equation is x=%f and y=%f",x,y);
    getch();
    }
    but after compiling the result is look like this .....why ....

    wnter the values of a,b,c=>6 5 4
    sqrt" DOMAIN error
    The quadratic equation is x=+NAN and y=+NAN


    its the program for to find out the result of the qudratic equation

    with regards
    anupam jamatia
    Last edited by Salem; 08-08-2006 at 05:57 AM. Reason: Change title and add code tags - still, indentation is crap

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That's it. I'm not helping ANYONE from now on if they aren't using CODE TAGS.

    Go read the forum guidelines until you figure out how to use code tags. Do not pass GO, do not collect $200.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    step 1) Use code tags

    step 2) Use a meaningful subject. "Help me" says nothing. Why would you be creating a thread if you didn't need help?

    EDIT: Ohhhhh, quzah beat me.
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Have you actually tried solving [6x2 + 5x + 4 = 0] manually?

    Other problems:
    int main()
    float x = {expression returning double}
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    > sqrt" DOMAIN error
    It means don't do square roots on negative numbers. You need to check this before calling sqrt() and print appropriate answers.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    NaN means Not a Number.
    Have a nice day.
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Returning Nan or Inf
    By magda3227 in forum C Programming
    Replies: 4
    Last Post: 07-01-2008, 05:41 PM
  2. nan disappear when printing
    By liats80 in forum C Programming
    Replies: 10
    Last Post: 02-03-2008, 01:17 PM
  3. double, NaN, and super small numbers
    By nbo10 in forum C Programming
    Replies: 5
    Last Post: 08-17-2007, 06:50 PM
  4. a question about nan
    By FOOTOO in forum C Programming
    Replies: 14
    Last Post: 04-26-2007, 01:19 PM
  5. Using NaN in c++
    By Hardboy in forum C++ Programming
    Replies: 3
    Last Post: 03-04-2003, 05:44 AM

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