Thread: Program the prints prime numbers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    14

    Program the prints prime numbers

    I need to make a program that prints all prime numbers between 3 and 100.
    Here is my code so far. Right now it only outputs the number 3. What is wrong with it? Thanks for any help.

    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {int num=3, checknum, remainder, answer=1;
    	do{checknum=2;
    		while(checknum<num-1)
    		{remainder=num%checknum;
    		if(remainder==0)
    		{answer=0;
    		continue;}
    		else
    		answer=1;
    		checknum++;
    		}
    		if(answer=1)
    		{cout<<""<<num;}
    		num++;
    	}while(num<101);
    	return 0;
    }
    Last edited by cloudstrife910; 09-22-2010 at 02:45 PM. Reason: forgot tags

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recuration Prime Numbers
    By megazord in forum C Programming
    Replies: 17
    Last Post: 05-17-2010, 08:56 AM
  2. Prime Numbers
    By Ahmed29 in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2008, 10:54 AM
  3. Help with program code re prime numbers
    By Anna Lane in forum C Programming
    Replies: 3
    Last Post: 11-16-2002, 10:48 AM
  4. Replies: 2
    Last Post: 09-11-2002, 05:00 PM
  5. Prime Numbers
    By cmangel518 in forum C++ Programming
    Replies: 13
    Last Post: 04-30-2002, 11:51 PM