Click here to Skip to main content
15,891,184 members
Home / Discussions / C#
   

C#

 
GeneralRe: Logic of prime numbers Pin
BillWoodruff3-Jan-15 11:57
professionalBillWoodruff3-Jan-15 11:57 
GeneralRe: Logic of prime numbers Pin
Richard MacCutchan3-Jan-15 21:05
mveRichard MacCutchan3-Jan-15 21:05 
GeneralRe: Logic of prime numbers Pin
BillWoodruff3-Jan-15 21:21
professionalBillWoodruff3-Jan-15 21:21 
GeneralRe: Logic of prime numbers Pin
Richard MacCutchan3-Jan-15 22:02
mveRichard MacCutchan3-Jan-15 22:02 
AnswerRe: Logic of prime numbers Pin
SledgeHammer012-Jan-15 14:16
SledgeHammer012-Jan-15 14:16 
GeneralRe: Logic of prime numbers Pin
Member 113371082-Jan-15 14:19
Member 113371082-Jan-15 14:19 
GeneralRe: Logic of prime numbers Pin
SledgeHammer012-Jan-15 14:32
SledgeHammer012-Jan-15 14:32 
GeneralRe: Logic of prime numbers Pin
Member 113371082-Jan-15 15:06
Member 113371082-Jan-15 15:06 
C#
Console.Write("Enter a Number : ");
           int num;
           num = Convert.ToInt32(Console.ReadLine());
           int k;
           k = 0;
           for (int i = 1; i <= num; i++)
           {
               if (num % i == 0)
               {
                   k++;
               }
           }
           if (k == 2)
           {
               Console.WriteLine("Entered Number is a Prime Number and the Largest Factor is {0}",num);
           }
           else
           {
               Console.WriteLine("Not a Prime Number");
           }
           Console.ReadLine();


you seem to be very smart. so heres one last question for you. In this situation, what does the k stand for? why is it that if k=2 then the number that was entered is prime?
GeneralRe: Logic of prime numbers Pin
SledgeHammer012-Jan-15 15:24
SledgeHammer012-Jan-15 15:24 
GeneralRe: Logic of prime numbers Pin
BillWoodruff3-Jan-15 11:59
professionalBillWoodruff3-Jan-15 11:59 
Questionhow can get number in a string in c# :(((((( Pin
mhd.sbt2-Jan-15 6:13
mhd.sbt2-Jan-15 6:13 
AnswerRe: how can get number in a string in c# :(((((( Pin
Pete O'Hanlon2-Jan-15 6:28
mvePete O'Hanlon2-Jan-15 6:28 
AnswerRe: how can get number in a string in c# :(((((( Pin
BillWoodruff2-Jan-15 7:43
professionalBillWoodruff2-Jan-15 7:43 
QuestionCan I write my own XBox 360 program? Pin
trantrum2-Jan-15 4:41
professionaltrantrum2-Jan-15 4:41 
AnswerRe: Can I write my own XBox 360 program? Pin
Richard MacCutchan2-Jan-15 4:53
mveRichard MacCutchan2-Jan-15 4:53 
AnswerRe: Can I write my own XBox 360 program? Pin
OriginalGriff2-Jan-15 5:00
mveOriginalGriff2-Jan-15 5:00 
GeneralRe: Can I write my own XBox 360 program? Pin
trantrum2-Jan-15 5:07
professionaltrantrum2-Jan-15 5:07 
GeneralRe: Can I write my own XBox 360 program? Pin
OriginalGriff2-Jan-15 5:13
mveOriginalGriff2-Jan-15 5:13 
GeneralRe: Can I write my own XBox 360 program? Pin
trantrum2-Jan-15 5:21
professionaltrantrum2-Jan-15 5:21 
GeneralRe: Can I write my own XBox 360 program? Pin
OriginalGriff2-Jan-15 5:25
mveOriginalGriff2-Jan-15 5:25 
AnswerRe: Can I write my own XBox 360 program? Pin
BillWoodruff2-Jan-15 6:56
professionalBillWoodruff2-Jan-15 6:56 
GeneralRe: Can I write my own XBox 360 program? Pin
trantrum2-Jan-15 9:20
professionaltrantrum2-Jan-15 9:20 
QuestionUnhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 4:28
turbosupramk32-Jan-15 4:28 
AnswerRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
Dave Kreskowiak2-Jan-15 4:35
mveDave Kreskowiak2-Jan-15 4:35 
GeneralRe: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. - why? Pin
turbosupramk32-Jan-15 5:07
turbosupramk32-Jan-15 5:07 

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.