File:  [CSRG BSD Unix] / 43BSD / usr.lib / learn / C / L14.1a
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:55 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43
BSD 4.3

#print
Using the familar "getnum.o" routine
write a program that reads numbers one per line and determines
for each if it is prime. Print "prime"
for a prime number and "composite" for a non-prime number.
Compile, test, and type "ready".
#once #create Ref
10039
17947
#once #create Ref1
prime
composite
#once cp %s/getnum.o .
#user
a.out <Ref >x1
#cmp x1 Ref1
#succeed
/* A slow but sure prime-tester */
main()
{
	int p, i, comp;

	while ((p = getnum()) >= 0) {
		comp = 0;
		for (i = 2; i*i <= p; i++)
			if (p%i == 0) {
				comp = 1;
				break;
			}
		if (comp)
			printf("composite\n");
		else
			printf("prime\n");
	}
}
#log
#next
15.1a 10

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.