Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Fill in the blank functions to complete this simple program.
- /* printarrays.c - prints some very simple arrays. */
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- /* Print an array of integers with a title. */
- void print_int_array(int *int_array, int n, char *title) {
- printf("%s\n", title);
- for(int i = 0; i < n; i++) {
- printf(" %d\n", int_array[i]);
- }
- }
- /* Fill an array of integers beginning with the value first, ending with or under the value last,
- and stepping by step. The final element filled may have value last, but no higher. It is up
- to the calling function to make sure that the combination of first, last and step makes sense,
- and that there is enough space in the array. Returns the number of items in the array. */
- int create_int_step_array(int *int_array, int first, int last, int step) {
- // Your code goes here – 20 points
- }
- /* Print the first ten squares of positive even numbers. */
- void print_even_squares(void) {
- int squares[10];
- int n;
- n = create_int_step_array(squares, 2, 20, 2);
- for(int i = 0; i < n; i++) {
- squares[i] = squares[i] * squares[i];
- }
- print_int_array(squares, n, "First ten squares of positive even numbers");
- }
- /* Print the first twenty squares of positive odd numbers. */
- void print_odd_squares(void) {
- // Your code goes here – 10 points
- }
- /* Print the first ten cubes of positive integers. */
- void print_cubes(void) {
- // Your code goes here – 10 points
- }
- int main(void) {
- print_even_squares();
- print_odd_squares();
- print_cubes();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement