Thread: Arithmetic Exception (Core Dumped) Help!

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    3

    Arithmetic Exception (Core Dumped) Help!

    Hi guys, I am doing a question which is as follow:

    Using this small set of five numbers: 2, 3, 4, 5, 6; there are 10 pairs that can be formed: (2,3), (2,4), (2,5), (2,6), (3,4), (3,5), (3,6), (4,5), (4,6) and (5,6). Six of these 10 pairs: (2,3), (2,5), (3,4), (3,5), (4,5), and (5,6) have no common factor other than one. Using the ratio of the counts as the probability we have:

    6/p2 = 6/10. Hence the estimated value of p is 3.1623, correct to four decimal places.

    As another example, given this set of 10 numbers {32391, 14604, 3902, 153, 292, 12382, 17421, 18716, 19718, 19895}, there are 24 pairs that have no common factor other than one, among a total of 45 pairs. We have:

    6/p2 = 24/45. Hence the estimated value of p is 3.3541, correct to four decimal places.

    I keep encountering the Arithmetic Exception (Core Dumped) problem. Could any kind soul please give me some advice? Thanks! Below is my programme:

    Code:
    #include <stdio.h>
    #include <math.h>
    #define N 50
    
    double estimate(int [], int);
    
    int main(void)
    {
            int arr[N],i,size;
            double pi;
    
            printf("Enter the size of the array:\n");
            scanf("%d", &size);
    
            for(i=0;i<size;i++)
            {
                    scanf("%d", &arr[i]);
            }
    
            pi = estimate(arr, size);
            printf("%lf", pi);
    
        return 0;
    }
    
    // Write a description of the function here
    double estimate(int arr[], int size)
    {
            int i,j,k,count,total_count=0,found=0;
            double pi;
            for(i=0;i<size-1;i++)
            {
                    for(j=i+1;j<size;j++)
                    {
                            total_count++;
                            count = 0;
                            if(arr[i] > arr[j])
                            {
                                    for(k=2;k<=arr[j];k++)
                                    {
                                            if(arr[i] % k == 0 && arr[j] % k == 0)
                                                    count++;
                                    }
                                    }
                            else
                            {
                                    for(k=2;k<=arr[i];k++)
                                    {
                                            if(arr[j] % k == 0 && arr[i] % k ==0)
                                                    count++;
                                    }
                            }
                            if(count==1)
                                    found++;
                    }
            }
    
            pi = sqrt(6 / (found/total_count));
    
            return pi;
    }
    Thanks for your help!
    Last edited by Salem; 10-07-2010 at 11:45 AM. Reason: TAGS

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Novice
    Join Date
    Jul 2009
    Posts
    568
    I'll hazard a guess and say that it's due to division by zero under some conditions at this line:
    Code:
    pi = sqrt(6 / (found/total_count));
    Add some printouts for value of (found / total_count), found and total_count before this line.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in Exceptions.h file during build of QuickFix library
    By arupsarkar in forum C++ Programming
    Replies: 3
    Last Post: 07-16-2010, 10:30 AM
  2. Bus Error (Core Dumped) with sscanf
    By saadahmed42 in forum C Programming
    Replies: 10
    Last Post: 04-12-2010, 01:28 PM
  3. couple of questions concerning multi core cpu's
    By Masterx in forum Tech Board
    Replies: 6
    Last Post: 10-07-2009, 10:39 AM
  4. Arithmetic exception
    By svaidya in forum C++ Programming
    Replies: 5
    Last Post: 01-17-2008, 03:39 AM
  5. Segmentation fault, core dumped
    By dweenigma in forum C Programming
    Replies: 2
    Last Post: 05-21-2007, 03:50 PM