Thread: Finding the cube root of a number.

  1. #1
    Registered User
    Join Date
    May 2018
    Posts
    10

    Post Finding the cube root of a number.

    Code:
    #include<stdio.h>
    #include<math.h>
    
    main()
    {
        float a,b;
        
        printf("Enter a number : ");
        scanf("%d",&a);
        
        b = pow(a,(1/3));
        
        printf("The cube root of a given number is : %f",b);
    }
    If cube root of a number is equal to raised to the power of 1/3. Then why is the program not finding the root and displaying it.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,669
    Try 1.0 / 3.0
    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.

  3. #3
    Registered User
    Join Date
    May 2018
    Posts
    10
    It is displaying zero.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,611
    In addition to Salem's comment, your scanf is completely wrong.

    Try calling this instead.
    scanf("%f", &b);

    Perhaps you need to link the math library? -lm
    Last edited by whiteflags; 05-02-2018 at 11:26 AM.

  5. #5
    Registered User
    Join Date
    May 2018
    Posts
    10
    No the user is asked to input the value of a so that value of b can determined. b is the cube root of a. Then how can be scanf wrong. According to your scanf what is the value of a.

  6. #6
    Registered User
    Join Date
    Apr 2017
    Location
    Quetzaltenango
    Posts
    82
    scanf("%f", &a);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finding root of a number
    By dvsumosize in forum C++ Programming
    Replies: 8
    Last Post: 03-07-2011, 03:05 AM
  2. A cube root program.
    By guest111 in forum C Programming
    Replies: 14
    Last Post: 04-27-2007, 09:37 PM
  3. cube root
    By gunshipolitico in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2005, 01:57 AM
  4. finding the square root of a number
    By Geo-Fry in forum C++ Programming
    Replies: 2
    Last Post: 03-27-2003, 07:46 PM
  5. Cube root
    By gahhhhh in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2002, 10:33 PM

Tags for this Thread