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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:08:41+00:00 2026-05-25T12:08:41+00:00

I have the following exercise program from a book. The book states that for

  • 0

I have the following exercise program from a book. The book states that for values x=10 and y=100, functions; min, max, incr and square are called 1, 91, 90 and 90 respectively. However, to me it looks like they are being called the following number of times, 1, 1, 1 and 0. Can someone explain to me the book numbers. Thanks.

#include <stdio.h>

int min(int x, int y){
    return x < y ? x : y;
}

int max(int x, int y){
    return x > y ? y : x;
}

void incr(int *xp, int v) {
    *xp += v;
}

int square (int x){
    return x*x;
}

int main(void){
    int i;
    int x = 10;
    int y = 100;
    int t = 0;

    for (i = min(x, y); i < max(x, y); incr(&i, 1)){
        t += square(i);
        printf("test %i", t);
    }
}
  • 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-05-25T12:08:42+00:00Added an answer on May 25, 2026 at 12:08 pm

    Well the loop is really (as x and y don’t change):

    for (i = 10; i < 100; incr(&i, 1))
    

    The the first statement executes only once – that’s why min is executed 1 time.
    The stop condition is executed once at the beginning and then after each iteration – so 91 times. The third statemnt is executed at the end of each iteration – so 90 times.

    So the book is correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF solution that consists of the following class libraries: Exercise.Services: Contains
I have the following exercise: Define a class named circle that accepts objects of
Hey, This is just a simple exercise from class that I decided to have
I'm currently learning about structs, so I have the following exercise: Set a Struct
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
I have the following exercise but am not sure on how I should begin.
Recently I've studied the backpropagation network and have done some manual exercise. After that,
From this guide , I have successfully run the sample exercise. But on running
I have the following program: module Main where import System (getArgs) import Control.Concurrent import
I'm trying to make the following exercise from Thinking in C++ Vol 2, witch

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.