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

  • Home
  • SEARCH
  • 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 7039945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:51:33+00:00 2026-05-28T01:51:33+00:00

This small C script checks if a number is a prime… Unfortunately it doesn’t

  • 0

This small C script checks if a number is a prime… Unfortunately it doesn’t fully work. I am aware of the inefficiency of the script (e.g. sqrt optimization), these are not the problem.

#include <stdio.h>

int main() {
  int n, m;

  printf("Enter an integer, that will be checked:\n"); // Set 'n' from commandline
  scanf("%d", &n); // Set 'n' from commandline

  //n = 5; // To specify 'n' inside code.

  for (m = n-1; m >= 1; m--) {
    if (m == 1) {
      printf("The entered integer IS a prime.\n");
      break;
    }
    if (n % m == 0) {
      printf("The entered integer IS NOT a prime.\n");
      break;
    }
  }
  return 0;
}

I tested the programm with a lot of numbers and it worked… Then I tried a bigger number (1231231231231236) which is clearly not a prime…
BUT: the program told me it was!?

What am I missing…?

  • 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-28T01:51:34+00:00Added an answer on May 28, 2026 at 1:51 am

    The number “1231231231231236” is too big to fit in an “int” data type. Add a printf statement to show what number your program thinks you gave it, and if that’s prime, your program works fine; else, you might have a problem that merits checking. Adding support for integers of arbitary size requires considerable extra effort.

    The reason you are having this problem is that intrinsic data types like int have a fixed size – probably 32 bits, or 4 bytes, for int. Given that, variables of type int can only represent 2^32 unique values – about 4 billion. Even if you were using unsigned int (you’re not), the int type couldn’t be used to store numbers bigger than around 4 billion. Your number is several orders of magnitude larger than that and, as such, when you try to put your input into the int variable, something happens, but I can tell you what doesn’t happen: it doesn’t get assigned the value 1231231231231236.

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

Sidebar

Related Questions

I have this small jquery script that does not work if I remove the
this is a small addition to the previous script, and this time I would
Work on this small test application to learn threading/locking. I have the following code,
I have a small script that checks a large list of domains for their
Backup Script Please check the link above, I wrote this small script in python.
I've got this small question - given a bitmask of weekdays (e.g., Sunday =
I have this small code library that I'm considering releasing into Open Source. I
I have this small SQL query. SELECT a.`id` , a.`title` , a.`date` , (
I have this small class called City that simply holds some information about a
We use this small utility method. But we don't like it. Since it's 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.