Thread: Prime #'s question. "Floating point exception" error.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User andrew89's Avatar
    Join Date
    Dec 2011
    Location
    Indiana, United States
    Posts
    80
    Started over, rewrote the majority of it using a dry-erase board. It works rather well now. Any thoughts, comments, suggestions, etc. are welcome and appreciated.
    Code:
    #include<stdio.h>
    #include<limits.h>
    
    int main()
    {
    short int yesno;
    long long int i,j;
    long long int x=3;
    long long int y=LLONG_MAX;
    
    FILE *fp;
    fp = fopen("output","w+");
    fprintf(fp,"1, 2, ");
    
    for(i=x;i<=y;i++)
    {
    yesno=0;
    for(j=2;j<=i/2;j+=2)
    	{
    	if(i%j==0)
    		{
    		yesno=1;
    		break;
    		}
    	}
    	if (yesno==0)
    		{
    		fprintf(fp,"%lld, ",i);
    		}
    	}
    fclose(fp);
    return 0;
    }
    Last edited by andrew89; 12-28-2011 at 10:34 AM. Reason: Forgot to use the updated code. Silly me.
    If, for some reason, I don't make any sense at all, it's highly likely that I've been up all night on some strange bender that isn't normal. I likely unarmed and far from dangerous. While I haven't been known to physically harm anyone or anything else, there have been unsubstantiated reports that I have driven others into both a hazy stupor as well as a blinding rage. Otherwise, I hope I helped.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 12-02-2007, 05:55 AM
  2. Replies: 7
    Last Post: 07-03-2007, 01:49 PM
  3. "Unlinked floating point" problem
    By sahil_m in forum C Programming
    Replies: 3
    Last Post: 08-02-2005, 12:21 PM
  4. "Unlimited" Length Floating Point Numbers
    By LuckY in forum C++ Programming
    Replies: 0
    Last Post: 03-22-2005, 07:49 PM
  5. "Floating Point : Overflow" ??
    By mellisa in forum C++ Programming
    Replies: 3
    Last Post: 02-15-2003, 06:41 PM