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 9014181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:26:54+00:00 2026-06-16T03:26:54+00:00

#include <cstdio> #include <ctime> int populate_primes(int array[]) { const int max = 1000000; char

  • 0
#include <cstdio>
#include <ctime>

int populate_primes(int array[])
{   
    const int max = 1000000; 
    char numbers[max+1];
    int count=1;
    array[0]=2;
    for(int i=max;i>0;i-=2)numbers[i]=0;
    for(int i=max-1;i>0;i-=2)numbers[i]=1;
    int i;  
    for(i=3;i*i<=max;i+=2){
        if(numbers[i]){
            for(int j=i*i;j<max+1;j+=i)numbers[j]=0;            array[count++]=i;
        }
    }
    int limit = max/2;
    for(;i<limit;i++)   if(numbers[i])array[count++]=i;
    return count;
}

int factorize(int number,int array[])
{
    int i=0,factor=1;
    while(number>0){
        if(number%array[i]==0){
            factor++;
            while(number%array[i]==0)number/=array[i];
        }
        i++;
    }
    printf("%d\n",factor);
    return factor;
}
int main()
{
    int primes[42000];
    const int max = 1000000;
    int factors[max+1];
    clock_t start = clock();
    int size = populate_primes(primes);
    factorize(1000,primes);
    printf("Execution time:\t%lf\n",(double)(clock()-start)/CLOCKS_PER_SEC);
    return 0;
}

I am trying to find the no. of factors using simple algo. The populate primes part is running okay , but the factorize part does not execute and gives the floating point exception error.

Please see the code and tell my mistake.

  • 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-16T03:26:55+00:00Added an answer on June 16, 2026 at 3:26 am

    You need to pass the size which you got from populate to factorize.
    factorize(int number, int array[], int size);
    problem is your array[] is not fully loaded, it is loaded only till size variable. So you may want to check for that.
    Also the logic inside factorize is wrong. You need to check (number > 1) rather than (number >0).

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

Sidebar

Related Questions

#include<cstdio> #include<stdlib.h> int main() { char* ptr=NULL; printf(%s,ptr); return 0; } It prints (null)
#include <iostream> #include <cstdlib> #include <cstdio> #include <ctime> int main(int argc, char* argv[]) {
#include <Windows.h> #include <cstdio> const int KEY=111; void encryptStrA(char* sometext) { int length; length=strlen(sometext);
#include <ctime> #include <cstdio> #include <sys/time.h> #include <iostream> using namespace std; int main() {
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include <cstdio> #include <string> void fun(const char* c) { printf(--> %s\n, c); } std::string
#include <cstdio> #include <QtCore/QProcess> int main (int argc, char** argv) { // if we
#include<iostream> #include<cstdio> using namespace std; int main() { int T; char J[100], S[100]; int
Code: #include <cstdio> class myc { int dummy; public: int si(){return sizeof(*this);} }; class
Test code: #include <cmath> #include <cstdio> const int N = 4096; const float PI

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.