Question: Edit the code so that it fufils the requirements. Create a C program file named longest _ streak.c . In that file, write a function
Edit the code so that it fufils the requirements.
Create a C program file named longeststreak.c In that file, write a function with the following signature: unsigned longeststreakint unsigned
The function takes an int array and its length as arguments and returns the longest streak. By longest streak, we mean the largest number of times the same value appears consecutively in the array. For example, if int test then longeststreaktest should return because the longest streak consists of consecutive values the value appears consecutive times If the length is the function should return
Hint: you can create a main method inside of longeststreak.c or in a separate c file for testing the longeststreak function while you develop it
Create a header file named longeststreak.h so that other code that wants to use your function can #include "longeststreak.h Include a header guard. Note: a header guard is not strictly necessary in this case since you only have declarations, not definitions, but it is good practice.
Commentout the main method from longeststreak.c if it exists and ensure there are no print statements in the longeststreak function.
longeststreak.h:
#ifndef LONGESTSTREAKH
#define LONGESTSTREAKH
unsigned longeststreakint arr unsigned length;
#endif LONGESTSTREAKH
longeststreak.c:
#include "longeststreak.h
unsigned longeststreakint arr unsigned length
if length return ;
unsigned maxstreak ;
unsigned currentstreak ;
for unsigned i ; i length; i
if arri arri
currentstreak;
else
if currentstreak maxstreak
maxstreak currentstreak;
currentstreak ;
if currentstreak maxstreak
maxstreak currentstreak;
return maxstreak;
int main
int test;
unsigned length sizeoftest sizeoftest;
unsigned result longeststreaktest length;
printfLongest streak: u
result; Expected output:
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
