4 Replies - 1822 Views - Last Post: 04 November 2006 - 04:17 AM Rate Topic: -----

#1 kavi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-November 06

Help! Prime Number

Post icon  Posted 03 November 2006 - 11:27 AM

I need help!!

I Can not invent the algorithm of this programm. Can someone help me? :)

input number "n" and the programm shows all prime number who is lesser than number "n" and whom can enounce like 2^k -1

This post has been edited by kavi: 03 November 2006 - 11:38 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Help! Prime Number

#2 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Help! Prime Number

Posted 03 November 2006 - 11:37 AM

Post the code you have completed so far and someone will be happy to help you.
Was This Post Helpful? 0
  • +
  • -

#3 kavi   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-November 06

Re: Help! Prime Number

Posted 03 November 2006 - 11:47 AM

#include <iostream>
int x (int n,int m); //deklaree visus mainiigos
using namespace std;

int main()
{
	int n, m=0;
	char exit;
	do
	{
		 cout << "\nInput number, \nthe programm will show \nall prime number who is \nlesserthan your input number \nand which can enounce like 2^k -1 ";
		 cin  >> n;
		 cout << "\nYour input number is : "  << n << endl; 
		 
		 ................................. <<< I can`t  invent what be writen in here
		 
		 cout << "\nPrime number wich is lesser than your nummber and \nwich enounce like 2^k -1 is  : "  << m << endl;
		 cout << "\nRepeat the programm <y/n> " << endl;
		 cin  >> exit;
	}
while (exit=='y');

return 0;
}

Was This Post Helpful? 0
  • +
  • -

#4 dorknexus   User is offline

  • or something bad...real bad.
  • member icon

Reputation: 1272
  • View blog
  • Posts: 4,625
  • Joined: 02-May 04

Re: Help! Prime Number

Posted 03 November 2006 - 03:13 PM

a prime number is a number which is divisible only by itself and one

thus the following algorithm, should verify whether a number is prime or not

bool isPrime(int num)
{
	 for (int i = 2;i < num;++i)
	 {
		  if (num % i == 0)
			   return false;
	 }

	 return true;
}

Was This Post Helpful? 0
  • +
  • -

#5 born2c0de   User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Re: Help! Prime Number

Posted 04 November 2006 - 04:17 AM

Quote

a prime number is a number which is divisible only by itself and one

or you can write the function using the exact definition that Dark_Nexus gave:
int isprime(int x)
{
   int i=2;
   while(x%i)i++;

   return (x==i);
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1