Arrays[ ] Problem Set

1.) Write C statements to accomplish each of the following:

1. Display the value of the seventh element of character array f.
2. Input a value into element 4 of single-subscripted floating-point array b.
3. Initialize each of the 5 elements of single-subscripted integer array g to 8.
4. Total the elements of floating-point array c of 100 elements.
5. Copy array a into the first portion of array b. Assume float a, b;
6. Determine and print the smallest and largest values contained in 99-element floating point array w.

2.) Write C statements that perform each of the following single subscripted array operations:

1. Initialize the 10 elements of the integer array counts to zeros.
2. Add 1 to each of the 15 elements of integer array bonus.
3. Read the 12 values of floating point array monthlyTemperatures from the keyboard.
4. Print the 5 values of integer array bestScores in column format.

3.) Find the error(s) in each of the following statements:

```
a.)  char str;
scanf("%s", str);    /* user types hello */

b.)  int a;
printf("\$d  %d   %d\n", a,  a,  a);

c.)  #define  SIZE   4

main()
{
float f[SIZE]  =  { 1.1,  10.01,  100.01,  1000.111,  109.54 };
int  b[SIZE - 5];
int  array_one[3.0];

d.)   double d;
d[1,9] = 2.345;

```

4.) What does the following program do?

```

#include
#define  SIZE  10

int  whatIsThis(Int  [ ],  int);

main()
{
int  total,  a[SIZE] = {1,  2,  3,  4,  5,  6,  7,  8,  9,  10};

total = whatIsThis(a, SIZE);
printf("Total of array elemnt values is %d\n", total);
return 0;
}

int whatIsThis( int b[ ], int size )
{
if (size = = 1)
{
return b;
}
else
{
return  b[ size  -  1 ]  +  whatIsThis(b, size  -  1);
}
}
```

5.) Write a function that computes and prints out the sums from the elements of an array of integers. Each element of the array contributes to one of the two sums, depending on whether the element itself is even or odd.

Your function definition should look something like this:

void print_sum ( int array_one[ ] , int size ) ;

6.) Write a program that keeps sales data for ten years by month. The two dimensional array should have a month index of size 12. Given this data, compute by sorted order the months of the year for which sales are best. ( sum January's for every year, sum February's for every year ....... etc ....... , then tell which months were best)

7.) What does the following program do?

```/* Array example problem */
#include <stdio.h>
#define SIZE 3

main()
{
int a[SIZE] = {29,  27,  23};
int i, pass, hold;

printf ("Data items in original order \n");

for (i = 0; i <= 2 ; i++) {
printf("%4d", a[i]);
}

for (pass = 1; pass <= 2; pass++)  {

for (i=0 ; i <= 1 ; i++) {   /* two compares */

if (a[i]  a[i + 1]) {
hold = a[i];
a[i] = a[i + 1];
a[i+1] = hold;
}
}
}

printf ("\nData items in new order \n");

for (i = 0; i <= 2 ; i++) {
printf("%4d", a[i]);
}

}
```

8.) Write a function that sums the even indexed elements and the odd indexed elements of an array of doubles. The function should print these sums out to the screen. Each element of the array contributes to one of the two sums, depending on whether the index of the element is even or odd.

The function definition should look something like this:

void print_sum ( double array_one[ ] , int size ) ;

```

```

9.) Write a program that finds the maximum and minimum elements of a two-dimensional array.

Do all of this within main( ).