Solution for Exercise 12-24
ex1224
#include <stdio.h>
#define SIZE 5
void showarray(int array[]);
void arrayinc(int array[]);
int main()
{
int n[] = { 1, 2, 3, 5, 7 };
puts("Original array:");
showarray(n);
arrayinc(n);
puts("After calling the arrayinc() function:");
showarray(n);
return(0);
}
void showarray(int array[])
{
int x;
for(x=0;x<SIZE;x++)
printf("%d\t",array[x]);
putchar('\n');
}
void arrayinc(int array[])
{
int x;
for(x=0;x<SIZE;x++)
array[x]++;
}
Notes
* The code uses the ++ increment operator at Line 34 to add one to the value of each array element. I could have also used the += assignment operator, as in array[x]+=1, but ++ is more to the point.
* Here is sample output:
Copyright © 1997-2025 by QPBC.
All rights reserved
