Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Complete the following functions to generate different sequences of numbers:

Complete the following functions to generate different sequences of numbers:
int* Fibonacci(int n)
• Create an array of integers and size n
• Fill in the array with the first n Fibonacci numbers. The Fibonacci sequence begins with O and then 1 follows. All subsequent
values are the sum of the previous two, ex: 0, 1, 1, 2, 3, 5, 8, 13.
• Return the array
int" Squares (int n)
• Create an array of integers and size n
• Fill in the array with the squares of 1 to n (inclusive). Ex: 1, 4, 9, ..., n²
• Return the array
int* Concatenate (int* array¹, int sizel, int* array2, int size2)
• Create an array of integers and size = size1 + size2
• Fill in the array with the elements of array1 followed by the elements of array2
• Return the array
main() reads the size of the Fibonacci and the squares sequences and calls the three functions above to create the arrays. Then main()
calls PrintArray() provided in the template to print the arrays.
Ex: If the input is:
64
the output is:
0 1 1 2 3 5
1 4 9 16
0 1 1 2 3 5 1 4 9 16
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 void PrintArray (int* array, int size) {
5 for (int j = 0; j < size; ++i) {
printf("%d ", array[j]);
}
6
7
8}
9
10 // Return the first n Fibonacci numbers
11 // fibonacci(0) = 0, fibonacci(1) = 1, fibonacci (2) = 1
12 // Ex: n = 5, seq = 0 1 1 2 3
13 int* Fibonacci(int n) {
14
15
16
17
18
19
20 }
21
int* seq;
int i;
/* Type your code here. 3/
return seq;
22 // Return sequence of squares for 1..n (inclusive)
23 // Ex: sqrn = 3, seq = 149
24 int* Squares (int n) {
25
int* seq;
26
27
28
29
30 }
31
/* Type your code here. */
return seq;
32 // Return an array that is a copy of array1 followed by
33 // the elements of array2
34 int* Concatenate(int* array1, int sizel, int* array2, int size2) {
35 int j;
36
37
int* seq;
38
2256&9&ARODB%
40
41}
46
43 int main(void) {
44
47
48
49
50
51
53
54
55
56
57
58
59
60
61
/* Type your code here. */
62
63
64
65
66
67
68}
69
return seq;
int fibn;
| || | || |
|| |
int sqrn;
scanf("%d %d", &fibn, &sqrn);
int* fibs;
int* sqrs;
int* conc;
fibs Fibonacci(fibn);
PrintArray (fibs, fibn);
printf("\n");
sqrs Squares (sqrn);
PrintArray (sqrs, sqrn);
printf("\n");
// sea of first fibn Fibonacci numbers
// Ex: fibn = 5, seq = 0 1 1 2 3
// number of squares starting with 1
// Ex: sqrn = 3, seq = 149
conc = Concatenate (fibs, fibn, sqrs, sqrn);
PrintArray (conc, fibn + sqrn);
printf("\n");
return 0;
expand button
Transcribed Image Text:Complete the following functions to generate different sequences of numbers: int* Fibonacci(int n) • Create an array of integers and size n • Fill in the array with the first n Fibonacci numbers. The Fibonacci sequence begins with O and then 1 follows. All subsequent values are the sum of the previous two, ex: 0, 1, 1, 2, 3, 5, 8, 13. • Return the array int" Squares (int n) • Create an array of integers and size n • Fill in the array with the squares of 1 to n (inclusive). Ex: 1, 4, 9, ..., n² • Return the array int* Concatenate (int* array¹, int sizel, int* array2, int size2) • Create an array of integers and size = size1 + size2 • Fill in the array with the elements of array1 followed by the elements of array2 • Return the array main() reads the size of the Fibonacci and the squares sequences and calls the three functions above to create the arrays. Then main() calls PrintArray() provided in the template to print the arrays. Ex: If the input is: 64 the output is: 0 1 1 2 3 5 1 4 9 16 0 1 1 2 3 5 1 4 9 16 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 void PrintArray (int* array, int size) { 5 for (int j = 0; j < size; ++i) { printf("%d ", array[j]); } 6 7 8} 9 10 // Return the first n Fibonacci numbers 11 // fibonacci(0) = 0, fibonacci(1) = 1, fibonacci (2) = 1 12 // Ex: n = 5, seq = 0 1 1 2 3 13 int* Fibonacci(int n) { 14 15 16 17 18 19 20 } 21 int* seq; int i; /* Type your code here. 3/ return seq; 22 // Return sequence of squares for 1..n (inclusive) 23 // Ex: sqrn = 3, seq = 149 24 int* Squares (int n) { 25 int* seq; 26 27 28 29 30 } 31 /* Type your code here. */ return seq; 32 // Return an array that is a copy of array1 followed by 33 // the elements of array2 34 int* Concatenate(int* array1, int sizel, int* array2, int size2) { 35 int j; 36 37 int* seq; 38 2256&9&ARODB% 40 41} 46 43 int main(void) { 44 47 48 49 50 51 53 54 55 56 57 58 59 60 61 /* Type your code here. */ 62 63 64 65 66 67 68} 69 return seq; int fibn; | || | || | || | int sqrn; scanf("%d %d", &fibn, &sqrn); int* fibs; int* sqrs; int* conc; fibs Fibonacci(fibn); PrintArray (fibs, fibn); printf("\n"); sqrs Squares (sqrn); PrintArray (sqrs, sqrn); printf("\n"); // sea of first fibn Fibonacci numbers // Ex: fibn = 5, seq = 0 1 1 2 3 // number of squares starting with 1 // Ex: sqrn = 3, seq = 149 conc = Concatenate (fibs, fibn, sqrs, sqrn); PrintArray (conc, fibn + sqrn); printf("\n"); return 0;
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education