* some tutorial and the ansi C book
[mascara-docs.git] / C / the.ansi.c.programming.language / c.programming.notes / homework / PS1.html
blobf85a25584b4d5f9ff0ca84239b9533d196884f4a
1 <!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
2 <!-- This collection of hypertext pages is Copyright 1995-7 by Steve Summit. -->
3 <!-- This material may be freely redistributed and used -->
4 <!-- but may not be republished or sold without permission. -->
5 <html>
6 <head>
7 <link rev="owner" href="mailto:scs@eskimo.com">
8 <link rev="made" href="mailto:scs@eskimo.com">
9 <title>Assignment #1</title>
10 </head>
11 <body>
12 <H1>Assignment #1</H1>
18 <B>Introductory C Programming
19 <br>
20 <br>
21 UW Experimental College
22 </B><br>
23 <br>
24 <B>Assignment #1
25 </B><p><B>Handouts:
26 </B></p><p>Syllabus
27 <br><a href="PS1.html">Assignment #1</a>
28 <br><a href="http://www.eskimo.com/~scs/cclass/progintro/top.html">A Short Introduction to Programming</a>
29 <br><a href="http://www.eskimo.com/~scs/cclass/mathintro/top.html">A Brief Refresher on Some Math Often Used in Computing</a>
30 <br><a href="http://www.eskimo.com/~scs/cclass/notes/sx1.html">Class Notes, Chapter 1</a>
31 <br><a href="http://www.eskimo.com/~scs/cclass/notes/sx2.html">Class Notes, Chapter 2</a>
32 <br><a href="http://www.eskimo.com/~scs/cclass/handouts/avcompilers/index.html">Available Compiler Options</a>
33 <br><a href="http://www.eskimo.com/~scs/cclass/handouts/errmsgs/top.html">Common Compiler Error Messages and Other Problems</a>
34 <br><a href="http://www.eskimo.com/~scs/cclass/handouts/cstepbystep/index.html">Compiling C Programs: Step by Step</a>
35 <p><B>Reading Assignment:
36 </B></p><p><a href="http://www.eskimo.com/~scs/cclass/progintro/top.html">A Short Introduction to Programming</a>
37 <br><a href="http://www.eskimo.com/~scs/cclass/notes/sx1.html">Class Notes, Chapter 1</a>
38 <br><a href="http://www.eskimo.com/~scs/cclass/notes/sx2.html">Class Notes, Chapter 2</a> (optional)
39 <br><a href="http://www.eskimo.com/~scs/cclass/handouts/cstepbystep/index.html">Compiling C Programs: Step by Step</a>
40 <p><B>Review Questions:
41 </B></p><OL><li>Approximately what is the line <TT>#include &lt;stdio.h&gt;</TT>
42 at the top of a C source file for?
43 <li>What are some uses for comments?
44 <li>Why is indentation important?
45 How carefully does the compiler pay attention to it?
46 <li>What are the largest and smallest values that can be reliably
47 stored in a variable of type <TT>int</TT>?
48 <li>What is the difference between the constants
49 <TT>7</TT>, <TT>'7'</TT>, and <TT>"7"</TT>?
50 <li>What is the difference between the constants
51 <TT>123</TT> and <TT>"123"</TT>?
52 <li>What is the function of the semicolon in a C statement?
53 </OL><p><B>Exercises:
54 </B>(easy to harder; do as many as you like, but at least two)
55 <p>1.
56 Get the ``Hello, world!'' program to work on your computer.
57 If you're using a Unix machine, the instructions in the notes should
58 get you started.
59 If you're using a commercial compiler on a home
60 computer, the compiler's instruction manuals should (really, <em>must</em>)
61 tell you how to enter, compile, and run a program.
62 (In either case, the
63 ``<a href="http://www.eskimo.com/~scs/cclass/handouts/csstepbystep/top.html">Compiling C Programs</a>''
64 handout should help, too.)
65 <p>2.
66 What do these loops print?
67 <pre>
68 for(i = 0; i &lt; 10; i = i + 2)
69 printf("%d\n", i);
70 </pre>
71 <pre>
72 for(i = 100; i &gt;= 0; i = i - 7)
73 printf("%d\n", i);
74 </pre>
75 <pre>
76 for(i = 1; i &lt;= 10; i = i + 1)
77 printf("%d\n", i);
78 </pre>
79 <pre>
80 for(i = 2; i &lt; 100; i = i * 2)
81 printf("%d\n", i);
82 </pre>
83 <p>3.
84 Write a program to print the numbers from 1 to 10
85 and their squares:
86 <pre>
87 1 1
88 2 4
89 3 9
90 ...
91 10 100
92 </pre>
93 <p>4.
94 Write a program to print this triangle:
95 <pre>
98 ***
99 ****
100 *****
101 ******
102 *******
103 ********
104 *********
105 **********
106 </pre>
107 Don't use ten <TT>printf</TT> statements; use two nested loops instead.
108 You'll have to use braces around the body of the outer loop if
109 it contains multiple statements:
110 <pre>
111 for(i = 1; i &lt;= 10; i = i + 1)
113 /* multiple statements */
114 /* can go in here */
116 </pre>
117 (Hint: a string you hand to <TT>printf</TT> does not have to contain the
118 newline character <TT>\n</TT>.)
119 </p><hr>
120 <hr>
122 This page by <a href="http://www.eskimo.com/~scs/">Steve Summit</a>
123 // <a href="copyright.html">Copyright</a> 1995-9
124 // <a href="mailto:scs@eskimo.com">mail feedback</a>
125 </p>
126 </body>
127 </html>