Click here to Skip to main content
15,916,945 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: How to send a message in TCP/IP? Pin
Michael Dunn2-Jul-06 8:55
sitebuilderMichael Dunn2-Jul-06 8:55 
GeneralRe: How to send a message in TCP/IP? [modified] Pin
mikanu2-Jul-06 10:29
mikanu2-Jul-06 10:29 
GeneralRe: How to send a message in TCP/IP? Pin
pShay2-Jul-06 20:22
pShay2-Jul-06 20:22 
GeneralRe: How to send a message in TCP/IP? Pin
Jun Du5-Jul-06 4:12
Jun Du5-Jul-06 4:12 
GeneralRe: How to send a message in TCP/IP? Pin
pShay5-Jul-06 20:30
pShay5-Jul-06 20:30 
Questionusing Templates and multiple inheritance in managed c++.net Pin
ajay kr. boosar1-Jul-06 4:48
ajay kr. boosar1-Jul-06 4:48 
QuestionFrames and Auto Navigation with WebBrowser2 Pin
Dave_Roach1-Jul-06 4:38
Dave_Roach1-Jul-06 4:38 
Questionbool isPrime (int Number) Pin
jon-801-Jul-06 0:41
professionaljon-801-Jul-06 0:41 
I'm trying to code a function that checks whether a number is a prime number.

When trying to implement a known algorithm...I'm getting unexpected results.

I know it's not managed c++, but I would appreciate help. Any ideas pls? Sigh | :sigh:



#pragma once
#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

bool isPrime (int Number)
{

/* hard-setting prime numbers */
if (Number <= 1) return false;

/* Algorithm: Sieve of Erastosthenes*/

int *mPrimeNumber;
mPrimeNumber = new int[Number + 1];
int iIndex;

/* initialize values */
for (iIndex = 0; iIndex <= Number; iIndex++)
{mPrimeNumber[iIndex] = 0;}

iIndex = 2;
mPrimeNumber[iIndex] = 1;
for (iIndex = iIndex * iIndex; iIndex <= Number; iIndex += 2)
{mPrimeNumber[iIndex] = 2;}

iIndex = 2;
while (iIndex <=Number)
{ iIndex++;
if (mPrimeNumber[iIndex]==2)
{mPrimeNumber[iIndex] = 1;
for (int iInnerIndex = iIndex; iInnerIndex <= Number; iInnerIndex += iIndex)
{mPrimeNumber[iIndex]= 2;}
}
}

// set return value
switch (mPrimeNumber[Number])
{ case 1:
return true;
break;
case 2:
return false;
break;
case 0:
cout << "Error!: " << Number << " not checked!!" << endl;
break;
default:
cout << "Error!: Invalid return value"<< endl;
}

delete [] mPrimeNumber;
};

void main ()
{
int iNumber = 0;
while(iNumber != 9999)
{
cout << "Enter an integer:" << endl;
cin >> iNumber;

// test isPrime function
if (isPrime(iNumber) !=0)
{cout << "Prime" << endl;}
else
{cout << "Not-Prime" << endl;}

}
}



Jon
QuestionWhere to start? Pin
Stober30-Jun-06 11:42
Stober30-Jun-06 11:42 
AnswerRe: Where to start? Pin
Michael Dunn30-Jun-06 23:07
sitebuilderMichael Dunn30-Jun-06 23:07 
Questionabout powerpoint reader Pin
xiahuang11929-Jun-06 17:49
xiahuang11929-Jun-06 17:49 
QuestionEnhance pointer precision Pin
coolice200229-Jun-06 8:27
coolice200229-Jun-06 8:27 
QuestionRe: Enhance pointer precision Pin
Jun Du29-Jun-06 9:11
Jun Du29-Jun-06 9:11 
QuestionRe: Enhance pointer precision [modified] Pin
coolice200229-Jun-06 20:49
coolice200229-Jun-06 20:49 
Questionhow do i use OpenCV code in windows forums [modified] Pin
zamco28-Jun-06 20:59
zamco28-Jun-06 20:59 
AnswerRe: how do i use OpenCV code in windows forums Pin
zamco29-Jun-06 15:59
zamco29-Jun-06 15:59 
QuestionQuestion about MC++ Marshall LParam to Struct Pin
ScottLeff26-Jun-06 10:38
ScottLeff26-Jun-06 10:38 
Question"Force file output" option in Visual Studio.NET Pin
dashprasannajit25-Jun-06 18:38
dashprasannajit25-Jun-06 18:38 
Questionproblem Facing with c++/cli arrays Pin
Nagaraju_Focus23-Jun-06 21:07
Nagaraju_Focus23-Jun-06 21:07 
AnswerRe: problem Facing with c++/cli arrays Pin
2bee 23-Jun-06 22:02
2bee 23-Jun-06 22:02 
Questionhelp me to create joystick controller Pin
nyquisttt23-Jun-06 4:07
nyquisttt23-Jun-06 4:07 
AnswerRe: help me to create joystick controller Pin
John M. Drescher23-Jun-06 4:37
John M. Drescher23-Jun-06 4:37 
GeneralRe: help me to create joystick controller Pin
nyquisttt26-Jun-06 21:56
nyquisttt26-Jun-06 21:56 
GeneralRe: help me to create joystick controller Pin
Jun Du27-Jun-06 7:11
Jun Du27-Jun-06 7:11 
GeneralRe: help me to create joystick controller Pin
mertadin16-Jul-06 23:12
mertadin16-Jul-06 23:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.