
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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;](https://content.bartleby.com/qna-images/question/5779ee7a-d811-43a6-ba75-7d41285b789d/8e3570b4-39bc-493d-953d-fb4f9f48dc67/4q0oh1q_thumbnail.png)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
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
- Do not use global variables for this assignment Choose descriptive variable names in all programs. Currency format. There should be no space between the $ sign and the first digit. In python, Write a program that uses a custom function named as you wish and the main function. In main, prompt the user for a first name and an integer less than 10 and then execute the custom function with these two inputs as arguments. The custom function should output one line displaying the name as many times as specified by the integer, separating each repetition of the name with a space.arrow_forwardFor the following questions, you are only allowed to use the following built-in functions: print(), range(), and len() and do python Create a code that uses a function that computes and displays theresult of a fibonacci sequence.arrow_forwardI need some help redoing this code, I want it to function a little differently than this. The code basically needs the following things: cannot use the power function, cannot use the sin function, must use header files (user defined functions), a loop must be used for factorial functions. Basically using these rules it should autmatically change the input of degrees to radians. The overall code should compute sin(x) using a taylor series expansion(using loops instead of using the factorial function) This is what I have, I know it works but I would like to change it.arrow_forward
- Use Matlab. It's a homework due today. "I paid for this service to assist me with homeworks."arrow_forwardGiven 3 integers and you have to use eval function to calculate the following a+b+c (a-b) /c a*b*c In jsarrow_forwardDetermine names for functions that do the following: Find the average of a set of numbers.arrow_forward
- An integer is said to be prime if it’s greater than 1 and divisible only by 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. a) Write a function that determines whether a number is prime. b) Use this function in a script that determines and prints all the prime numbers between 1 and 10,000. How many of these 10,000 numbers do you really have to test before being sure that you have found all the primes? Display the results in a <textarea>. c) Initially, you might think that n/2 is the upper limit for which you must test to see whether a number is prime, but you need go only as high as the square root of n. Why? Rewrite the program using the Math.sqrt method to calculate the square root, and run it both ways. Estimate the performance improvement. Please write the code in JavaScript HTML5.arrow_forwardAn integer is said to be prime if it’s greater than 1 and divisible only by 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. a) Write a function that determines whether a number is prime. b) Use this function in a script that determines and prints all the prime numbers between 1 and 10,000. How many of these 10,000 numbers do you really have to test before being sure that you have found all the primes? Display the results in a <textarea>. c) Initially, you might think that n/2 is the upper limit for which you must test to see whether a number is prime, but you need go only as high as the square root of n. Why? Rewrite the program using the Math.sqrt method to calculate the square root, and run it both ways. Estimate the performance improvement. Please write the code in Javasript HTML5 formatarrow_forward# Write a function called ex3(n) which# 1. accepts as an input parameter an integer between 1 and 100# 2. Calculates and print the mersenne primes between 1 and this number# See en.wikipedia.org/wiki/Mersenne_prime for details# 3. Invoke ex3(16) to print resultsarrow_forward
- how to write a function that takes an integer n and prints all of the integers between 1 and n which are multiple of 5 using while looparrow_forwardThe range () function can be used together with for, to generate a sequence of float numbers. TrueFalse What are the values that range (1, 5, 2) will generate? 1,3,51, 2, 3, 4, 51,2, 3,41,3arrow_forwardWrite a function in python that takes an acrostic as the input and will return the secret message to the user. Include optional arguments to state what makes the first line, as well as what position should be used.a) SATOR\nAREPO\nTENET\nOPERA\nROTAS\n1. Use each index position 0 through 4 b)Elizabeth it is in vain you say\t“Love not” – thou sayest it in so sweet a way:\tIn vain those words from thee or L.E.L.\tZantippe’s talents had enforced so well:Ah! If that language from thy heart arise,\tEndymion, recollect, when Luna tried\tTo cure his love – was cured of all beside\tHis folly – pride – and passion – for he died.“An Acrostic” by Edgar Allen Poearrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education