Thread: Prime number, wired problem?

  1. #1
    Registered User
    Join Date
    Jul 2016
    Posts
    8

    Prime number, wired problem?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    //#include "prime.h"
    
    
    int IsPrime(int a){
     int b=2, c=0;
     
     for (b=2; b<a; b++){
      if (a%b==0){
       c++;
       break;
      }
     }
     //return (c);
    }
    
    
    int main(int argc, char *argv[]) 
    {
     int main(int argc, char *argv[]) {
        int n;
        scanf("%d",&n);
        if(IsPrime(n) == 0)
            printf("%d is prime\n", n);
        else
            printf("%d is not prime\n", n);
    
    
     system("pause"); 
     return 0;
    }

    I don't know what the problem is, first the problem was the #include prim.h, but I got rid of it so that was solved. Then I got this message:
    "expected declration at end of input"

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You appear to have a typo error with your main function, i.e.,
    Code:
    int main(int argc, char *argv[]) 
    {
     int main(int argc, char *argv[]) {
    You only need to write it once.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2016
    Posts
    8
    yep, I relised, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Right-prime number algorithm problem
    By shufu7-11 in forum C Programming
    Replies: 5
    Last Post: 11-07-2011, 06:41 PM
  2. Prime number problem
    By Antigloss in forum C Programming
    Replies: 13
    Last Post: 06-04-2005, 02:56 AM
  3. Replies: 3
    Last Post: 03-29-2005, 04:24 PM
  4. problem with my prime number program
    By datainjector in forum C Programming
    Replies: 4
    Last Post: 07-12-2002, 12:30 PM
  5. Prime Number problem
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2001, 08:00 PM

Tags for this Thread