|
|
1.1 ! root 1: #print ! 2: Using the familar "getnum.o" routine ! 3: write a program that reads numbers one per line and determines ! 4: for each if it is prime. Print "prime" ! 5: for a prime number and "composite" for a non-prime number. ! 6: Compile, test, and type "ready". ! 7: #once #create Ref ! 8: 10039 ! 9: 17947 ! 10: #once #create Ref1 ! 11: prime ! 12: composite ! 13: #once cp %s/getnum.o . ! 14: #user ! 15: a.out <Ref >x1 ! 16: #cmp x1 Ref1 ! 17: #succeed ! 18: /* A slow but sure prime-tester */ ! 19: main() ! 20: { ! 21: int p, i, comp; ! 22: ! 23: while ((p = getnum()) >= 0) { ! 24: comp = 0; ! 25: for (i = 2; i*i <= p; i++) ! 26: if (p%i == 0) { ! 27: comp = 1; ! 28: break; ! 29: } ! 30: if (comp) ! 31: printf("composite\n"); ! 32: else ! 33: printf("prime\n"); ! 34: } ! 35: } ! 36: #log ! 37: #next ! 38: 15.1a 10
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.