for (Index = 0; Index < STRING_LENGTH-1 && (C1=getchar()) != '\n' && C1 != EOF; Index++) {
MyString[Index]=C1;
}
the order is useful in that it's necessary to check there
is space to store the character before reading it. If not
the evaluation will stop before the getchar().
| Operator | Associativity |
|---|---|
| | |
| () func() [] -> . | left to right |
| ! ~ ++ -- + - (<type>) * & sizeof | right to left |
| * / % | left to right |
| + - | left to right |
| << >> | left to right |
| < <= > >= | left to right |
| == != | left to right |
| & | left to right |
| ^ | left to right |
| | | left to right |
| && | left to right |
| || | left to right |
| ?: | right to left |
| = <operator>= | right to left |
| , | left to right |
<expression1> || <expression2> || <expression3>is seen as
(<expression1> || <expression2>) || <expression3>while
<variable1> += <variable2> += <expression1>is seen as
<variable1> += (<variable2> += <expression1>)
<variable> = <variable> <operation> <expression>can be rewritten in the form
<variable> <operation>= <expression>if <operation> is one of +, -, *, /, %, <<, >>, &, ^, |.
if (<expression1>)
<variable> = <expression2>;
else <variable> = <expression3>;
can be rewritten in the form
<variable> = <expression1> ? <expression2> : <expression3>
if (<expression>) {
<true stuff>
}
if (<expression>) {
<true stuff>
} else {
<false stuff>
}
for (<exp1>;<exp2>;<exp3>) {
<statement>
}
<exp1>
while (<exp2>) {
<statement>
<exp3>;
}
for (<exp1>;<exp2>;<exp3>) {
<statement>
}
if (<everything went ok>) {
exit(EXIT_SUCCESS);
} else {
exit(EXIT_FAILURE);
}
for ( )
for ( )
for ( )
if (disaster)
goto error;
.........
error: /*----Sort out the mess */
28 2 1992
Date following 28:02:1992 is 29:02:1992
Input Output
========== ======
10 1234 1234
8 77 63 (the value of 77 in base 8, octal)
2 1111 15 (the value of 1111 in base 2, binary)
The base will be less than or equal to 10.
interest = capital * interest_rate / 100;
and is added to the capital sum by
capital += interest;
Print out money values as dollars (cents / 100.0) accurate to two decimal places. Print out a floating value for the value with compound interest for each year up to the end of the period. Print output year by year in a form such as:
Original sum 30000.00 at 12.5 percent for 20 years
Year Interest Sum
----+-------+--------
1 3750.00 33750.00
2 4218.75 37968.75
3 4746.09 42714.84
4 5339.35 48054.19
5 6006.77 54060.96
6 6757.62 60818.58
7 7602.32 68420.90
8 8552.61 76973.51
9 9621.68 86595.19
10 10824.39 97419.58
Inital value is 9
Next value is 28
Next value is 14
Next value is 7
Next value is 22
Next value is 11
Next value is 34
Next value is 17
Next value is 52
Next value is 26
Next value is 13
Next value is 40
Next value is 20
Next value is 10
Next value is 5
Next value is 16
Next value is 8
Next value is 4
Next value is 2
Final value 1, number of steps 19
If the input value is less than 1, print a message containing the word
Error and perform an exit(0);.
Numbers of characters:
a 3 ; e 2 ; i 0 ; o 1 ; u 0 ; rest 17
Percentages of total:
a 13%; e 8%; i 0%; o 4%; u 0%; rest 73%
Read characters to end of data using a construct such as
char ch;
while ((ch = getchar()) >= 0) {
/* ch is the next character */
....
}
to read characters one at a time using getchar() until
a negative value is returned.
Read
a
file
of
English
text
and
print
it
out
one
int i1 = 27;
int i2 = 29;
if (i1++ >= --i2) {
i1++;
printf("%d %d\n",i1++,i2--);
} else {
i2++;
printf("%d %d\n",--i1,++i2);
}
printf("%d %d\n",i1,i2);
for (Index = 1;Index < MAX;Index++) {
printf("%d\n",Index);
Total += Index;
}
Index = 1;
while (Index < MAX) {
printf("%d\n",Index);
Total += Index;
Index++;
}
Index = 1;
while (Index < 30) {
if (Index % 2 == 0) {
Index = Index < 10 ? ++Index : Index +3;
continue;
}
Index = (Index << 1) + 1;
if (Index % 6 == 0) {
break;
}
printf("%d\n",Index);
}