Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8573899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:21:18+00:00 2026-06-11T19:21:18+00:00

I created a program that will use a dynamic array by using pointer to

  • 0

I created a program that will use a dynamic array by using pointer to find the max and min from a set for integer that the user will enter.

I actually can get the output of max, but not for min; I found out my dynamic array will result to 0 after the calculation from the function of max, and made my min became the value of the assigned value of min.

I have no idea why it is like this – I tried many ways, but these were useless so can someone explain why, and provide a solution if possible or give me some hint for how to get through the solution?


Thank your replies

seem like my code had confused to your

Sorry

the program intent to get the maximum and minimum digits from an amount of integers

From I what I tried to say is after calculation from the function of max, the data from the dynamic array would become 0, and when program go through the function of min, it would not gonna run because the data from dynamic array had been set to 0

So actually what I wanna ask is is there anyway to make the data from the dynamic array not become to 0 after the function of max?

Sorry for my poor English

#include <iostream>
using namespace std;

void max(int*, int);
void min(int*, int);

int main()
{
   int *ptr;
   int i;
   int size;

   cout << "how many integer: ";
   cin >> size;

   ptr = new int[size];

   for (i = 0; i < size; i++)
   {
      cout << "integer#" << i << ": ";
      cin >> *ptr + i;
   }

   max(ptr, size);
   min(ptr, size);

   delete [] ptr;

   return;
}

void max(int* ptr, int size)
{
   int i;
   int j;
   int max = 0;

   for (i = 0; i < size; i++)
   {
      while (*ptr + i != 0)
      {
         j = *ptr + i % 10;

         if (j > max)
         {
            max = j;
         }

         *ptr + i /= 10;
      }
   }

   cout << max << endl;
}

void min(int* ptr, int size)
{
   int i;
   int j;
   int min= 0;

   for (i = 0; i < size; i++)
   {
      while (*ptr + i != 0)
      {
         j = *ptr + i % 10;

         if (j < min)
         {
            min= j;
         }

         *ptr + i /= 10;
      }
   }

   cout << min<< endl;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:21:19+00:00Added an answer on June 11, 2026 at 7:21 pm

    I do not know what compiler you have used, but your code is not even compiling without some modifications on my GCC 4.6.

    1. All *ptr + i becomes *(ptr + i).
    2. return; at the end of main() becomes return 0;.

    The other issue is that in function void min(int* ptr, int size), you are initializing min as 0. What you should really do is int min = std::numeric_limits<int>::max(); so that min has the highest possible integer value. Don’t forget the #include <limits>.

    Here is a code that finds the minimum digit and maximum digit without modifying the original array (a good practice),

    void max(int* ptr, int size) {
        int i;
        int j;
        int temp;
        int max = 0;
    
        for(i = 0; i < size; i++) {
            temp = *(ptr + i);
            while (temp != 0) {
                j = temp % 10;
                if (j > max)
                    max = j;
                temp /= 10;
            }
        }
    
        cout << max << endl;
    }
    
    void min(int* ptr, int size) {
        int i;
        int j;
        int temp;
        int min = 10;
    
        for(i = 0; i < size; i++) {
            temp = *(ptr + i);
            while (temp != 0) {
                j = temp % 10;
                if (j < min)
                    min = j;
                temp /= 10;
            }
        }
    
        cout << min<< endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i created an exercise program that create a dynamic menu from json. and then,
I created a server program that will be started as root. After it is
I am contemplating writing a program that will move some newly created dirs to
I am trying to create a program that will get data directly from socket
I am trying to create a program that will be passed input data from
I created a program that more or less holds an array of strings as
I'm using encryption in my program, that decrypts files if it needs to use
I have created a program in Java using eclipse that contains a couple of
I am creating a program that I will use to help my customers recover
I need to create a program that will download files from FTP Server and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.