Description In Part 3, write two functions to compute and print the values of an
ID: 3753329 • Letter: D
Question
Description In Part 3, write two functions to compute and print the values of an Arithmetic sequence and the Leonardo sequence with the following function headers: void artithmeticSequence(int start, int diff, int end) where start is the first value of the arithmetic sequence; diff is the difference between two consecutive values in the arithmetic sequence; and the last value of the arithmetic sequence void leonardoSequence (int start, int end) where the first value of the Leonardo sequence is greater than or equal to start and the last value of the Leonardo sequence is less than or equal to end except in the following cases: if e output should start with 11_3. If start equals 2, then the sequence output should start with 1_3_5 The main program calls the functions ArithmeticSequence and LeonardoSequence three times each as follows artithmeticSequence(3, 2, 17); artithmeticSequence(-17, 7, 37); artithmeticSequence (e, 29, 199); leonardoSequence(1, 137); leonardoSequence(2, 69) leonardoSequence (9, 177); Output The output must be exactly the same as the output sample bellow. There is one new-line character at the end (n) Sample Input 1 E Sample Output 1 No input Arithneticsequence:_-17_-18_-3411 1825_32 Arithneticsequence:_8_29_58_87_ 116_145_174 LeonardoSequence:_1_1_3_5_9_15_25_41 67_199 LeonardoSequence:_1_3_5_9_15_25_41 67 LeonardoSequence:_9_15_25_41 67_189_177 Hint include includeExplanation / Answer
You provided some typo program will print for (3,2,17) as well i am 100% sure please cross check with your teacher.
Code:
#include<stdio.h>
//function is used to calculate leonardo number
int leonardo(int n)
{
if (n == 0 || n == 1)
return 1;
return leonardo(n - 1) + leonardo(n - 2) + 1;
}
void arithmeticSequence(int start,int diff,int end)
{
printf("ArithmeticSequence:");
for(int i = 0; start < end; i++) {
printf("_%d ", start);
//Print number if it is greater than start and less than end
start= start + diff;
}
printf("_ ");
}
void leonardoSequence(int start,int end){
int num=start-1;
if(start!=1&&start!=2)
num=1;
int val=0;
printf("LeonardoSequence:");
while(val<end){
val=leonardo(num);
//Print leonardo number if it is greater than start and less than end
if(val<end&&val>=start-1)
printf("_%d ", val);
num++;
}
printf("_ ");
}
int main() {
arithmeticSequence(3,2,17);
arithmeticSequence(-17,7,37);
arithmeticSequence(0,29,199);
leonardoSequence(1,137);
leonardoSequence(2,69);
leonardoSequence(9,177);
}
Output:
ArithmeticSequence:_3 _5 _7 _9 _11 _13 _15 _
ArithmeticSequence:_-17 _-10 _-3 _4 _11 _18 _25 _32 _
ArithmeticSequence:_0 _29 _58 _87 _116 _145 _174 _
LeonardoSequence:_1 _1 _3 _5 _9 _15 _25 _41 _67 _109 _
LeonardoSequence:_1_3 _5 _9 _15 _25 _41 _67 _
LeonardoSequence:_9 _15 _25 _41 _67 _109 _