0% found this document useful (0 votes)
11 views1 page

Tutorial 5

Uploaded by

xuanvinhmel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Tutorial 5

Uploaded by

xuanvinhmel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

HIT365 C Programming – Tutorial 5

1. Write statements to accomplish the following:


a) Define table to be an integer array and to have 3 rows and 3 columns. Assume the
symbolic constant SIZE has been defined to be 3.
b) How many elements does the array table contain? Print the total number of elements.
c) Use a for repetition statement to initialize each element of table to the sum of its subscripts.
Assume the integer variables x and y are defined as control variables.
d) Print the values of each element of array table. Assume the array was initialized with the
definition:
int table[ SIZE ][ SIZE ] ={ { 1, 8 }, { 2, 4, 6 }, { 5 } };

2. Find the error in each of the following program segments and correct the error.
a) #define SIZE 100;
b) SIZE = 10;
c) Assume int b[ 10 ] = { 0 }, i;
for ( i = 0; i <= 10; i++ ) {
b[ i ] = 1;
}
d) #include <stdio.h>;

3. Use a single-subscripted array to solve the following problem. A company pays its
salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their
gross sales for that week. For example, a salesperson who grosses $3000 in sales in a week
receives $200 plus 9% of $3000, or a total of $470. Write a C program (using an array of
counters) that determines how many of the salespeople earned salaries in each of the
following ranges (assume that each salesperson’s salary is truncated to an integer amount):
a) $200–299
b) $300–399
c) $400–499
d) $500–599
e) $600–699
f) $700–799
g) $800–899
h) $900–999
i) $1000 and over

4. Label the elements of 2-by-3 double-subscripted array commission to indicate the order in
which they’re set to one by the following program segment:
for ( row = 0; row <= 1; row++ )
for ( column = 0; column <= 2; column++ )
commission[ row ][ column ] = 1;

5. A palindrome is a string that is spelled the same way forward and backward. Some
examples of palindromes are: “radar,” “able was i ere i saw elba,” and, if you ignore blanks,
“a man a plan a canal panama.” Write a recursive function testPalindrome that returns 1 if the
string stored in the array is a palindrome and 0 otherwise. The function should ignore spaces
and punctuation in the string.

You might also like