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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:02:36+00:00 2026-05-31T12:02:36+00:00

I’m working on C programming assignment to implement Sieve of Eratosthenes without using the

  • 0

I’m working on C programming assignment to implement Sieve of Eratosthenes without using the square root function of C. Below is my output and my professors output, I’m not sure what in my code is causing it to be wrong. Any ideas?

Here’s the expected output

Program initiated
   1   2   3   5   7  11  13  17  19  23  29  31
  37  41  43  47  53  59  61  67  71  73  79  83
  89  97 101 103 107 109 113 127 131 137 139 149
 151 157 163 167 173 179 181 191 193 197 199 211
 223 227 229 233 239 241 251 257 263 269 271 277
 281 283 293 307 311 313 317 331 337 347 349 353
 359 367 373 379 383 389 397 401 409 419 421 431
 433 439 443 449 457 461 463 467 479 487 491 499
 503 509 521 523 541 547 557 563 569 571 577 587
 593 599 601 607 613 617 619 631 641 643 647 653
 659 661 673 677 683 691 701 709 719 727 733 739
 743 751 757 761 769 773 787 797 809 811 821 823
 827 829 839 853 857 859 863 877 881 883 887
Program terminated

Here’s my output:

Program initiated
   1  37  41  43  47  53  59  61  67  71  73  79
  83  89  97 101 103 107 109 113 127 131 137 139
 149 151 157 163 167 173 179 181 191 193 197 199
 211 223 227 229 233 239 241 251 257 263 269 271
 277 281 283 293 307 311 313 317 331 337 347 349
 353 359 367 373 379 383 389 397 401 409 419 421
 431 433 439 443 449 457 461 463 467 479 487 491
 499 503 509 521 523 541 547 557 563 569 571 577
 587 593 599 601 607 613 617 619 631 641 643 647
 653 659 661 673 677 683 691 701 709 719 727 733
 739 743 751 757 761 769 773 787 797 809 811 821
 823 827 829 839 853 857 859 863 877 881 883 887
Program terminated

Here is my code:

#include <stdio.h>

void zap(int data[], int divisor)
{
    for(int i=0;i<900;i++)
    {
        if(data[i]%divisor==0) // if mod is not 0, 0 out the index. 
        {
            data[i] = 0; 
        }
    }
}
// the display method 
void display(int data[])
{
    int count = 0; // init counter on the out side
    for(int i=0;i<900;i++)
    {
        if(data[i]>0)// don't print 0s
        {
            printf("%4d",data[i]);// print the data in a column 

            count++;// increment count 

            if(count==12) // print rows and columns 
            {
                count=0; // reset count
                printf("\n"); // print new line 
            }
        }
    }
    if(count<12)// we terminate loop and we now need print a new line 
    {
        printf("\n"); 
    }
}

int main()
{   
    // start the program, with a message
    printf("Program initiated\n"); 

    // needs to be 900 long 
    int primes[900];

    // populate the array 
    for(int i=1; i <= 900; i++)
    {
            primes[i] = i; 
    }

    // elminate the bad numbers 
    for(int i=2; i < 35; i++)
    {
        zap(primes,i); 
    }

    // display the array. 
    display(primes);

    // print the end message    
    printf("Program terminated\n"); 

    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-05-31T12:02:37+00:00Added an answer on May 31, 2026 at 12:02 pm

    well you can can use something like this:

    (initialize sieve to be a big enough bool-array with each entry set to true – as I want to keep it simple set sieve[0] = false; sieve[1] = false;

    for(int i = 2; i < endOfNumbers; i++)
    {
       if (sieve[i] == false) continue;
       for (int m = 2*i; m < endOfNumbers; m += i)
          sieve[m]=false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT

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.