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

#print
Using the "getnum" routine on "getnum.o", write a program
that reads a list of positive numbers and prints their sum.  Stop reading
numbers when "getnum" returns a negative or zero value.
Compile and test your program; then type "ready".
#once #create Ref
5 43 293 400 75 832 903 33
#once cp %s/getnum.o .
#user
a.out <Ref >xxx
grep 2584 xxx >/dev/null
#succeed
/* Read numbers and count */
main()
{
	int s, n;

	s = 0;
	while ((n=getnum()) > 0)
		s += n;
	printf("Sum is %d\n", s);
}
#log
#next
14.2b 5
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.