Like Tree3Likes
  • 1 Post By tabstop
  • 2 Post By AndrewHunter

Can't use <math.h>

This is a discussion on Can't use <math.h> within the C Programming forums, part of the General Programming Boards category; Hi I'm learning C and now I want to use certain maths functions such as square root. But I can't ...

  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,185
    Why not print resultat instead of nombre1?
    CommonTater likes this.

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    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,866
    Quote Originally Posted by quzah View Post
    Looks like C to me.
    Quzah.
    Lol...the only language you actually understand.
    quzah and CommonTater like this.
    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, 10:19 AM
  2. math.h
    By tsutharssan in forum C Programming
    Replies: 3
    Last Post: 07-03-2009, 03:24 PM
  3. some math help
    By jrahhali in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-11-2005, 09: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

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