c# - Determine whether a number contains specific prime factors -
below code, , can't work way should.
i have find prime numbers (this works fine). then, if prime numbers 7 , 3
(63 = 7 * 3 * 3
or 7 = 7
) number magical, , if contains others (98 = 7 * 7 * 2
or 42 = 7 * 3 * 2
) it's not.
i'm kind of stuck here:
if (b != 7 && b != 3) console.writeline(k); else console.writeline(j);
i don't know how fix it. here whole code:
string k="isnt magical"; string j = "is magical"; int a, b; console.writeline("vnesite svoje stevilo: "); = convert.toint32(console.readline()); (b = 2; > 1; b++)/ if (a % b == 0) { while (a % b == 0) { /= b; } if (b != 7 && b != 3) console.writeline(k); else console.writeline(j); }
you printing "isnt magical"
or "is magical"
every factor. code should this:
string k = "isnt magical"; string j = "is magical"; int a, b; console.writeline("vnesite svoje stevilo: "); = convert.toint32(console.readline()); var allmagical = true; for(b = 2; > 1; b++) if(a % b == 0) { while(a % b == 0) /= b; if(b != 7 && b != 3) allmagical = false; } console.writeline(allmagical ? j : k);
Comments
Post a Comment