2014-02-25 3 views
0
00: 599 
01: 298 
02: 738 
03: 598 
04: 297 
05: 395 
06: 730 
07: 825 
08: 597 
09: 295 
10: 717 
11: 597 
12: 196 
13: 397 
14: 592 
15: 393 
16: 600 
17: 598 
18: 902 
19: 598 
20: 196 
21: 398 
22: 594 
23: 397 
24: 600 
25: 593 
26: 196 
27: 393 
28: 595 
29: 604 
30: 593 
31: 717 
32: 598 
33: 196 
34: 398 
35: 594 
36: 397 
37: 600 
38: 000 
91: 005 
92: 000 // DAT 000 
93: 000 // Counter 
94: 002 // DAT 002 
96: 001 // DAT 001 - plus 1 
97: 002 // DAT 002 - dividor 
98: 002 // DAT 001 - incrementor 
99: 050 // DAT 10 - max 

안녕 얘들 아, LMC는 사용자 입력에 의해 소수를 찾을 수

내가 ~ 100 사이의 소수를 찾을 수있는 코드를 가지고,하지만 난 만 발견 프로그램에이를 다시 사투를 벌인거야 사용자 입력 사이.

나는 서로 하나 개의 숫자를 뺄 계획을 가지고 있었고, 너희들은 어떤 조언을 어떻게 가야해야합니까 다음 2, 3, 4, 5

에 의해 그 번호를 나눌? 나는 코멘트의 부족에 대해 사과한다.

+0

이 번호에 대해 무엇입니까? –

+0

@LukaRahne, 흠, 네가 무엇을 요구하는지 모르겠다. 사용자 입력에는 제한이 없습니다. – l33tspeak

답변

1

면책 조항 : 본인의 원래 코드가 무엇인지 알지 못합니다. 숫자 코드를 잘 읽지 않아서입니다. 다음은 내가 직접 쓴 primes.lmc입니다. (주로 주석)


번호 :

# Prime number finder. Prints all prime numbers between the numbers the user inputs (min, then max). 

# Min 
     INP 
     SUB ONE 
     STA NUM 

# Max 
     INP 
     STA MAX 

# Main checking loop. Check each number from NUM to MAX. 
TLOOP LDA NUM 

# Have we done all MAX numbers? 
     SUB MAX 
     BRZ HALT 

# Increment to next number to check. 
     LDA NUM 
     ADD ONE 
     STA NUM 

# Reset divisor. 
     LDA ONE 
     STA DIV 

# Check NUM for primeness by dividing all numbers from 2 to NUM - 1 into it. 
DLOOP LDA DIV 

# Increment to next divisor. 
     ADD ONE 
     STA DIV 

# Have we checked up to the number itself? 
     LDA DIV 
     SUB NUM 
     BRZ PRIME 

# Setup for divide function. 
     LDA NUM 

# Modulus function: accumulator % DIV. 

MODULUS SUB DIV 
     BRP MODULUS 
     ADD DIV 

# Remainder is now in the accumulator. If its zero, NUM is not prime. 
     BRZ NPRIME 
     BRA DLOOP 

# If its prime, print it. 
PRIME LDA NUM 
     OUT 

# Go back to the top. 
NPRIME BRA TLOOP 

# End of program. 
HALT HLT 

NUM  DAT 1 
DIV  DAT 1 
ONE  DAT 1 
MAX  DAT 

제 1 사용자 입력은 최소한 두 번째 최대 (포함)이다.


(13에서 23로, specter에) 실행 :

Running

관련 문제