Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:59:15+00:00 2026-06-13T21:59:15+00:00

I am trying to write a program to approximate pi. It basically takes random

  • 0

I am trying to write a program to approximate pi. It basically takes random points between 0.00 and 1.00 and compares them to the bound of a circle, and the ratio of points inside the circle to total points should approach pi (A very quick explanation, the specification goes in depth much more).

However, I am getting the following error when compiling with gcc:

Undefined                       first referenced
symbol                          in file
pow                             /var/tmp//cc6gSbfE.o
ld: fatal: symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

What is happening with this? I’ve never seen this error before, and I don’t know why it’s coming up. Here is my code (though I haven’t fully tested it since I can’t get past the error):

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
    float x, y;
    float coordSquared;
    float coordRoot;
    float ratio;
    int n;
    int count;
    int i;

    printf("Enter number of points: ");
    scanf("%d", &n);

    srand(time(0));

    for (i = 0; i < n; i++) {
        x = rand();
        y = rand();

        coordSquared = pow(x, 2) + pow(y, 2);
        coordRoot = pow(coordSquared, 0.5);

        if ((x < coordRoot) && (y < coordRoot)) {
            count++;
        }
    }

    ratio = count / n;
    ratio = ratio * 4;

    printf("Pi is approximately %f", ratio);

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:59:18+00:00Added an answer on June 13, 2026 at 9:59 pm

    use -lm during compilation(or linking) to include math library.

    Like this: gcc yourFile.c -o yourfile -lm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a program that displays the integers between 1 and
I'm trying to write a program that takes input of - hexadecimals, octals, and
I am trying to write a program that takes an input of of n
I was trying to write a program that would display the prime numbers between
I'm trying write a program that takes a list of names, sorts those names,
I'm trying to write a program to call functions inside my .so library in
I'm trying write a program that takes a list of names, sorts those names,
Im trying to write a program that takes a txt file as input, and
I'm trying to write a program that would convert celcius to fahrenheit and visa-versa.
I am trying to write a program that will prompt you to enter someone's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.