Thread: Find the error, please.

  1. #1
    Registered User
    Join Date
    Apr 2017
    Posts
    5

    Red face Find the error, please.

    I don't know where I did mistake.

    Code:
    #include<stdio.h>
    #include<math.h>
    
    int main()
    {
        printf("%f",pow(11.5,2));
    
        return 1;
    }

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    806
    Quote Originally Posted by Suvivor View Post
    I don't know where I did mistake.

    Code:
    #include<stdio.h>
    #include<math.h>
    
    int main() 
    {
        printf("%f",pow(11.5,2));
    
        return 1;
    }
    What makes you think it doesn't work? What do you think the printed value should be?

    pow() takes two doubles. "2" should be "2.0", and a program returns 0 rather than 1 if the program works correctly. Returning a non-zero value to the O/S indicates an error, if the return value is checked by the calling program or process.

  3. #3
    Registered User
    Join Date
    Apr 2017
    Posts
    5
    hahaha...Now, I see what I did. It's because I was at my head that 11.5 * 11.5 was 23.

    Sorry man.
    Last edited by Suvivor; 04-30-2017 at 09:49 AM.

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    806
    Quote Originally Posted by Suvivor View Post
    hahaha...Now, I see what I did. It's because I was at my head that 11.5 * 11.5 was 23.

    Sorry man.
    Correct! pow() is a multiplication function!

  5. #5
    Registered User
    Join Date
    Apr 2017
    Posts
    5
    I have a question... I would like to calculate a^2 = b^2 + c^2... but don't to have variable or loops. Only simple code.

    Code:
    #include<stdio.h>
    #include<math.h>
    int main()
    {
        printf("%f",pow(11.5,2) + pow(6.3,2));
    
    
        return 1;
    }
    now, how I raise a??

  6. #6
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    It's overkill to use pow to square a number. Just multiply the number by itself. You will need the sqrt function, though. And depending on your system, you might have to add -lm (that's a lowercase L) to the end of your compile command to include the math library.
    Code:
    #include <stdio.h>
    #include <math.h>
     
    int main() {
        double b = 11.5;
        double c = 6.3;
        double a_squared = b * b + c * c;
        double a = sqrt(a_squared);
        printf("%lf\n", a);
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I get an error but could not find it, please help
    By miralay in forum C Programming
    Replies: 9
    Last Post: 12-12-2015, 01:05 PM
  2. help find my error?
    By baconator218 in forum C++ Programming
    Replies: 13
    Last Post: 10-30-2015, 01:19 AM
  3. Can't find any error
    By Khokhar in forum C Programming
    Replies: 2
    Last Post: 03-09-2013, 09:44 AM
  4. Can't find the error
    By Sid_TheBeginner in forum C Programming
    Replies: 6
    Last Post: 11-03-2012, 11:53 AM
  5. Can't seem to find the error here.
    By DavidP in forum C++ Programming
    Replies: 5
    Last Post: 12-30-2008, 01:26 PM

Tags for this Thread