Lecture5_code

# Lecture5_code - for(i = 3 i<=(nNumber 6/5 i = 2...

This preview shows page 1. Sign up to view the full content.

private void cmdFindPrimes_Click( object sender, EventArgs e) { Int32 i; Int32 nNumber; try { nNumber = Convert .ToInt16(txtNumber.Text); } catch { MessageBox .Show( "Error converting input!!!Default set to 2" ); nNumber = 2; } if (nNumber >= 2) MessageBox .Show( "Prime number: " + 2); for (i = 3; i <= nNumber; i+=2) { CheckNumber(i); //just call the method instead of the code below //bool prime = true; //Int32 a; //int nr = i; //for (a = 3; a < nr && prime == true; a += 2) //{ // if (nr % a == 0) // prime = false; //} //if (prime == true) // MessageBox.Show("Prime numbers smaller than " + i + " are: " + nr);
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } for (i = 3; i <= (nNumber* 6)/5; i += 2) { CheckNumber(i); //bool prime = true; //Int32 a; //int nr = i; //for (a = 3; a < nr && prime == true; a += 2) //{ // if (nr % a == 0) // prime = false; //} //if (prime == true) // MessageBox.Show("Prime number: " + nr); } } public void CheckNumber( Int32 nr) { bool prime = true ; Int32 a; for (a = 3; a < nr && prime== true ; a+=2) { if (nr % a == 0) prime = false ; } if (prime == true ) MessageBox .Show( "Prime number: " + nr ); }...
View Full Document

## This note was uploaded on 04/13/2010 for the course CIVIL 2oi4 taught by Professor Lamiar during the Fall '10 term at McMaster University.

Ask a homework question - tutors are online