Thread: Can't use <math.h>

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    19

    Can't use <math.h>

    Hi I'm learning C and now I want to use certain maths functions such as square root. But I can't make it work. It just send me back the number I write.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
        double resultat = 0, nombre1 = 100;
    
        printf("Square root : \n");
        scanf("%lf", &nombre1);
        resultat = sqrt(nombre1);
    
        printf("%lf", nombre1);
    
    return 0;
    
    }
    If I wirte square root 100 it just send me back 100, 49 sends back 49 and so on.

    How can I make it work ? What about pow function ? It doesn't seem to work either.

    Thanks a lot !

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Why not print resultat instead of nombre1?

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by zakiuz View Post
    Hi I'm learning C and now I want to use certain maths functions such as square root. But I can't make it work. It just send me back the number I write.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
        double resultat = 0, nombre1 = 100;
    
        printf("Square root : \n");
        scanf("%lf", &nombre1);
        resultat = sqrt(nombre1);
    
        printf("%lf", nombre1);
    
    return 0;
    
    }
    For starters you could print out the answer vice the input value:
    Code:
       resultat = sqrt(nombre1);
    
       printf("%lf", nombre1);
    Maybe you should print resultat vice nombre1 here.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    19
    I really got to pay more attention ! Thank you tabstop.

    P.S: I forgot to translate the code in english I kept it in french lol

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by zakiuz View Post
    I forgot to translate the code in english I kept it in french lol
    Looks like C to me.


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

  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by quzah View Post
    Looks like C to me.
    Quzah.
    Lol...the only language you actually understand.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  7. #7
    Registered User
    Join Date
    Sep 2011
    Posts
    19
    The variables name lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ and Math
    By darren78 in forum C++ Programming
    Replies: 2
    Last Post: 07-08-2010, 09:19 AM
  2. math.h
    By tsutharssan in forum C Programming
    Replies: 3
    Last Post: 07-03-2009, 02:24 PM
  3. some math help
    By jrahhali in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-11-2005, 08:48 PM
  4. Basic Math Problem. Undefined Math Functions
    By gsoft in forum C Programming
    Replies: 1
    Last Post: 12-28-2004, 03:14 AM
  5. Math in C++
    By Soccerman1234 in forum C++ Programming
    Replies: 5
    Last Post: 01-22-2004, 12:34 PM