Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function called max_consecutive_integers() that accepts a two-dimensiona

ID: 3694593 • Letter: W

Question

Write a function called max_consecutive_integers() that accepts a two-dimensional array of signed integers, the number of rows, the number of columns as input parameters, and two pointers as output parameters (one of these pointers is actually a pointer to a pointer, i.e. two stars!).
5. (BONUS - 20 pts) Write a function called max consecutive integers () that accepts a two-dimensional array of signed integers, the number of rows, the number of columns as input parameters, and two pointers as output parameters (one of these pointers is actually a pointer to a pointer, i.e. two stars!). The function finds the maximum consecutive sequence of one integer. The first pointer stores the address the start of the maximum consecutive sequence of the same integer. The second indirectly stores the number the same consecutive integers in a row. These sequences may wrap from one row to the next. For example ([Sxxxx] denotes address value) Row/Column $1004 $1024 $1044 1064 1008 $1028 $1048 1068 $1000 1012 1032 $1052 1072 1036 $1056 1076 1020 1060 The function should store the address of row 0, column 3 ($1012) via the first pointer, and 5 (2, 2, 2, 2, 2) indirectly via the second pointer.

Explanation / Answer

Ans;

#include<iostream>

#include<cstdio>

#define pf(x) printf("%d ",x)

#define sf(x) scanf("%d",&x)

using namespace std;

void max_consecutive_integers(int **arr,int r,int c,int **start,int **end)

{

     int i,j,max=1,temp=1;

     int **newstart=arr;

     start=arr;

     end=arr;

    

    //function to calculate the max consecutive integers

     for(i=0;i<r;i++)

    {

                    for(j=0;j<c;j++)

                    {

                                    if(i==0 && j == 0)

                                            continue;

                                    if(j == 0 && i>0)

                                    {

                                         //if the number changes change the end and start points if new max is found

                                         if(a[i][j] ! = a[i-1][c-1])

                                         {

                                                    if(max<temp)

                                                    {

                                                                max=temp;

                                                                end=a+i*c + j-1;

                                                                start=newstart;

                                                                newstart=a+i*c + j;

                                                                temp = 1;

                                                    }

                                                    else

                                                    {

                                                                temp++;

                                                                newstart=a+i*c + j;

                                                    }

                                         }

                                    }

                                    else

                                    {

                                        if(a[i][j] ! = a[i][j-1])

                                         {

                                                    if(max<temp)

                                                    {

                                                                max=temp;

                                                                end=a+i*c + j-1;

                                                                start=newstart;

                                                                newstart=a+i*c + j;

                                                                temp = 1;

                                                    }

                                                    else

                                                    {

                                                                temp++;

                                                                newstart=a+i*c + j;

                                                    }

                                         }

                                    }

                                                   

                    }

    }

    //check if last range is the max range

    if(max<temp)

                                                    {

                                                                max=temp;

                                                                end=a+i*c + j-1;

                                                                start=newstart;

                                                                newstart=a+i*c + j;

                                                                temp = 1;

                                                    }

                                                    else

                                                    {

                                                                temp++;

                                                                newstart=a+i*c + j;

                                                    }

}

    

int main()

{

    int r,c;

    cout<<" Enter number of rows";

    cin>>r;

    cout<<" Enter number of columns";

    cin>>c;

    int arr[r][c];

    int i,j;

   

    //taking input elements

    cout<<"enter elements";

    for(i=0;i<r;i++)

    {

                    for(j=0;j<c;j++)

                    {

                                    cin>>arr[i][j];

                    }

    }

    int **start,**end;

    max_consecutive_integers(arr,r,c,start,end);

    cout<<" Maximum Distance of Consecutive integers is from address: "<<start<<" to address: "<<end;

    return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote