Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Lab 8 - Part 1 - Exploring Arrays
- *** Your Name Here ***
- */
- #include <stdio.h>
- #define MAX_SIZE 10 /* Maximum number of items in table */
- /* Fill the table with the desired number of items */
- void fillTable(int list[], /* output - list of n integers */
- int size) /* input - number of items to fill */
- {
- int index;
- for (index = 0; index < size; index++)
- {
- list[index] = index * index * index;
- }
- }
- /* Display the table of cubes */
- void showTable(int list[], /* input - list of n integers */
- int size) /* input - number of items to show */
- {
- /* Find sum of cubes. */
- int sumCubes = 0;
- int index;
- for (index = 0; index < size; index++)
- {
- sumCubes += list[index];
- }
- /* Display each cube and the sum of all cubes. */
- printf("N\tCUBE\n");
- for (index = 0; index < size; index++)
- {
- printf("%d \t %d \n", index, list[index]);
- }
- printf("\nSum of cubes is %d\n", sumCubes);
- }
- /* Obtain input from user and call helper functions */
- int main(void)
- {
- int cubes[MAX_SIZE]; /* an array of integers */
- int numItems; /* desired number of items in list */
- printf("How many numbers should be cubed? ");
- scanf("%d", &numItems);
- fillTable(cubes, numItems);
- showTable(cubes, numItems);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement