Question
#include using namespace std; int *gdarry(int); //pointer to array int gmode(int *, int); // function for mode void disa(int *, int); // function to display
#include
int *gdarry(int); //pointer to array int gmode(int *, int); // function for mode void disa(int *, int); // function to display the array
int main() { int num; //vairable for number of integers int *ptr; // pointer int mode; // variable for mode cout<<"Please enter the number of integers you want processed: "; cin>>num; ptr=gdarry(num); cout<<" Numbers stored in array ";
disa(ptr,num); //stores num into array mode=gmode(ptr, num); if (mode==-1) cout<<"None of the values repeat "; else cout<<"The most frequent mode value is: " < return 0; } int gmode (int *ptr, int num) { int mode =-1; // stopping condition int current; int cnt; for (int i = 0; i < num; i++) //outer loop { current =*(ptr+i); cnt = 0; for (int j=0; j int *gdarry(int num) { int *ptr = new int [num]; for (int i = 0; i < num; i++) { cout<<"Enter the integer " << (i+1)<< ": "; cin>> *(ptr +i); while(*(ptr + i) <0) //input validation for negative { cout<<"Enter a positive integer " << (i+1) <<":"; cin>>*(ptr +i); } } return ptr; } void disa (int ptr[], int num) { for (int i = 0; i< num; i++) cout<<*(ptr+1)<<" "; cout< The array keeps returning the first number inputted instead of the full numbers of the array. For example, input 3 first number is 1 it would display 1 1 1 instead of 1 3 5.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started