Title: Answer
1Answer
a. unsigned int b. If your expectations on
yearly salary are not very high, a simple
unsigned int variable would work. If you feel you
have potential to go above 65,535, you probably
should use a long. (Have faith in yourself use a
long.) c. float (If you are only going to use
whole numbers, use either int or long.) d.
Definitely a signed field. Either int, long, or
float. See answer for 1d.
2Answer
The only changes needed in the Listing are the
following 17 printf("\nd
d", a, b) 18
printf("\nd d", a, b)
19 printf("\nd d", a, b)
20 printf("\nd d", a, b)
21 printf("\nd d", a, b)
3Answer
The following code fragment is just one of many
possible examples. It checks to see if x is
greater than or equal to 1 and if x is less than
or equal to 20. If these two conditions are met,
x is assigned to y. If these conditions are not
met, s is not assigned to y therefore, y remains
the same. if ((x gt 1) (x lt
20)) y x
4Answer
if (x lt 1 x gt 10) statement
5Answer
We did not do what this exercise asked however,
you can get the answer to the question from this
nested if. (You also could have indented this
differently.) if(age lt 21)
printf("You are not an adult")
else if(age gt 65)
printf("You are a senior citizen!")
else printf("You
are an adult")
6Question 1 Answer
If you look at the syntax boxes provided, you can
see that any of the three can be used to solve a
looping problem. Each has a small twist to what
it can do, however. The for statement is best
when you know that you need to initialize and
increment in your loop. If you only have a
condition that you want to meet, and you are not
dealing with a specific number of loops, while is
a good choice. If you know that a set of
statements needs to be executed at least once, a
do...while might be best. Because all three can
be used for most problems, the best course is to
learn them all and then evaluate each programming
situation to determine which is best.
7Question 2 Answer
You can nest as many loops as you want. If your
program requires more than two loops, however,
consider using a function instead. You might find
sorting through all those braces difficult, and a
function is easier to follow in code.
8Question 3 Answer
You can nest if, for, while, do...while, or any
other command. You will find that many of the
programs you try to write will require that you
nest at least a few of these.
9Exercise Answer
int x for(x 1 x lt 100 x 3)
10Exercise Answer
int x 1 while(x lt 100) x 3
11Exercise Answer
int ctr 1 do ctr 3 while(ctr lt
100)
12Exercise Answer
STDIO.H contains the prototypes for the standard
input/output functions. printf(), puts(), and
scanf() are three of these standard functions.
Try running a program without the STDIO.H header
and see the errors and warnings you get.
13Exercise Answer
This is an easy mistake to make. Unpredictable
results can occur if you forget the address of
operator. For now know that if you omit the
address of operator, scanf() doesn't place the
entered information in your variable, but in
some other place in memory. This could do
anything from apparently having no effect at all
to locking up your computer so that you have to
reboot.
14Exercise Answer
puts() automatically adds the newline, printf()
does not. printf("\n")
puts(" ")
15Exercise Answer
char c1, c2 int d1
scanf("c u c", c1, d1, c2)
16Exercise Answer
Your answer may vary.
includeltstdio.hgt int x
int main(void)
puts("Enter an integer value")
scanf("d", x) printf("\nThe value
entered is d", x) return
0
17Exercise Answer
include ltstdiod.hgt float x,
y int main(void)
puts("Enter two values ")
scanf("f f", x, y)
printf("\nThe product is f", x y)
return 0
18Exercise Answer
includeltstdio.hgt int count,
temp long total 0 / Use
type long to ensure we don't /
/ exceed the maximum for
type int. / int main(void)
for (count 1 count lt 10
count)
printf("Enter integer d ", count)
scanf("d", temp)
total temp
printf("\n\nThe total is d",
total) return 0