Advertisement
Guest User

Untitled

a guest
Feb 19th, 2021
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. Fill in the blank functions to complete this simple program.
  2.  
  3.  
  4. /* printarrays.c - prints some very simple arrays. */
  5.  
  6.  
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11.  
  12. /* Print an array of integers with a title. */
  13.  
  14. void print_int_array(int *int_array, int n, char *title) {
  15. printf("%s\n", title);
  16. for(int i = 0; i < n; i++) {
  17. printf(" %d\n", int_array[i]);
  18. }
  19. }
  20.  
  21.  
  22.  
  23. /* Fill an array of integers beginning with the value first, ending with or under the value last,
  24. and stepping by step. The final element filled may have value last, but no higher. It is up
  25. to the calling function to make sure that the combination of first, last and step makes sense,
  26. and that there is enough space in the array. Returns the number of items in the array. */
  27.  
  28.  
  29. int create_int_step_array(int *int_array, int first, int last, int step) {
  30. // Your code goes here – 20 points
  31. }
  32. /* Print the first ten squares of positive even numbers. */
  33. void print_even_squares(void) {
  34. int squares[10];
  35. int n;
  36. n = create_int_step_array(squares, 2, 20, 2);
  37. for(int i = 0; i < n; i++) {
  38. squares[i] = squares[i] * squares[i];
  39. }
  40. print_int_array(squares, n, "First ten squares of positive even numbers");
  41. }
  42.  
  43. /* Print the first twenty squares of positive odd numbers. */
  44.  
  45. void print_odd_squares(void) {
  46. // Your code goes here – 10 points
  47. }
  48.  
  49. /* Print the first ten cubes of positive integers. */
  50.  
  51. void print_cubes(void) {
  52.  
  53. // Your code goes here – 10 points
  54.  
  55. }
  56. int main(void) {
  57. print_even_squares();
  58. print_odd_squares();
  59. print_cubes();
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement