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 8787591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:55:45+00:00 2026-06-13T21:55:45+00:00

I have to find the maximum and the minimum using a sentinel controlled repetition.

  • 0

I have to find the maximum and the minimum using a sentinel controlled repetition.

“maximum” is not working properly. Can anyone help me with some clue about what’s wrong in my code?

#include<stdio.h>

int main() { 
  int number;
  int min;
  int max;

  do {
    printf("Enter a number (-1 to quit): ");
    scanf("%d",&number);
    if( number >= 0 ) {
      if(number < min )
        min = number;
      if( number > max )
        max = number;

    }
    else if( number < 1 )
      printf("the number is not valid \n");
  } 

  while( number != -1 );

  printf("Minimum=%d\n",min);
  printf("Maximum=%d\n",max);

  system("pause");

  return 0;
}
  • 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-13T21:55:46+00:00Added an answer on June 13, 2026 at 9:55 pm

    The value of your variables not initialized were 2674276, all numbers were smaller so your min was fine

    but no number was bigger than this so it was your max.

    You need to initialize your min and your max with the first number

    I would do something like

    max = -1
    min = -1
    
    do {
        printf("Enter a number (-1 to quit): ");
        scanf("%d",&number);
        if( number >= 0 ) {
          if(max == -1)
          {
             max = number //Means it's the first time so your max and min are the first number
             min = number
          }
          else
          {
             if(number < min )
                min = number;
             if( number > max )
              max = number;
    
          }
        }
        else if( number < 1 )
          printf("the number is not valid \n");
      } 
    
      while( number != -1 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a matrix using vector and iterator, how can I find maximum
I was wondering how can I find minimum and maximum values from a dataset,
I have to find some patters from a XML file, but i am unable
I have a list of words and i have to find the minimum word
I'm having some trouble with an SQL statement that have to find the number
How do I find the maximum (or minimum) of two integers in Postgres/SQL? One
I am new to programing and can not find or know what to search
I have data that looks like this. And I want to find the maximum
I am evaluating datamining packages. I have find these two so far: RapidMiner Weka
i have to find the shortest distance between the railway stations- given is the

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.