Solution using stdio.h in the main function
in Other Math Topics by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

Here is some C-code which will do that for you.

You may need to update the fopen() and itoa() functions, depending upon your compiler. But they shouild still run OK.

Just copy out the code below and paste it into your compiler/IDE

in the next answer.

 

 

// This code will open a console window for user input

// the user will be invited to enter an integer (from the keyboard)

// the code will initially assign the 1st user-entered integer as the

// value of both maximum and minimum values

// thereafter, there will be two distinct values - one max and the other min.

// both positive and negative values may be entered

// to terminate the program, the user should enter the value 0 (zero)

 

#include <stdio.h>

#include <limits.h>

#include <string.h>

#include <stdlib.h>

 

 

void collect(int* n);

int check_value();

 

The rest of the code follows below

by Level 11 User (81.5k points)

int main()

{

       int num_min = INT_MAX, num_max = INT_MIN, N;

       char num_min_str[256], num_max_str[256];

 

       FILE *fp;

 

       if((fp=fopen("maxminvals","w")) == NULL)

       {

              printf("Unable to open a file for writing to\n");

              return(-1);   // exit the program

       }                           // use -1 return value to indicate an error

                                    // although that is pretty uneccessary here

                                    // in this stand alone code

       do

       {

              collect(&N);  // send the address of the variable N to the function collect()

 

              if (N < num_min)     // on the first run through this loop

                     num_min = N;  // num_min and num_max will both hold

              if(N > num_max)             // the same value of N

                     num_max = N;

              printf("Minimum number is: %d, Maximum number is: %d\n",num_min,num_max);

       }while (N!=0);

​The rest of the main() function is in the next answer

// since the data is to be written to a text file

       // then convert the integer values to strings

       itoa(num_min,num_min_str,10);

       itoa(num_max,num_max_str,10);

 

       // write data to file

       fwrite(num_min_str,sizeof(num_min_str),1,fp);

       fwrite(num_max_str,sizeof(num_max_str),1,fp);

 

       // now finish off by closing the file

       fclose(fp);

       return(0);    // exit the program

}

 

The two sub-routines now

void collect(int* n) // collect input from the user

{

       printf("Enter an integer, positive or negative: ");

       *n = check_value();  // check that the user is inputting a valid integer value

}

 

int check_value()    // ensure that the user always enters only an integer value

{

       int x;

    float check;

 

    reprocess: // this is a goto construct label

    scanf_s("%f", &check);

    x=check;  // you may get warnings here (from compiler) because of possible loss of data

    if (x!=check)

    {

         printf("\nThis is not an integer number, please insert an integer!\n\n");

         goto reprocess;    // don't use goto unless very simple and uninvolved with other code!

    }                                      // goto statements are best avoided

    return x;

}

Related questions

2 answers
2 answers
asked Jun 10, 2013 in Word Problem Answers by anonymous | 1.3k views
3 answers
asked May 6, 2012 in order of operations by anonymous | 2.7k views
0 answers
asked Apr 12, 2012 in Algebra 2 Answers by anonymous | 1.2k views
2 answers
1 answer
asked Mar 2, 2013 in Word Problem Answers by anonymous | 337 views
2 answers
asked Nov 23, 2016 in Word Problem Answers by HelpMe | 2.5k views
1 answer
asked Sep 12, 2012 in Word Problem Answers by anonymous | 790 views
Welcome to MathHomeworkAnswers.org, where students, teachers and math enthusiasts can ask and answer any math question. Get help and answers to any math problem including algebra, trigonometry, geometry, calculus, trigonometry, fractions, solving expression, simplifying expressions and more. Get answers to math questions. Help is always 100% free!

Most popular tags

algebra problems solving equations word problems calculating percentages math problem geometry problems calculus problems math fraction problems trigonometry problems rounding numbers simplifying expressions solve for x order of operations probability algebra pre algebra problems word problem evaluate the expression slope intercept form statistics problems factoring polynomials solving inequalities 6th grade math how to find y intercept equation of a line sequences and series algebra 2 problems logarithmic equations solving systems of equations by substitution dividing fractions greatest common factor square roots geometric shapes graphing linear equations long division solving systems of equations least to greatest dividing decimals substitution method proving trigonometric identities least common multiple factoring polynomials ratio and proportion trig identity precalculus problems standard form of an equation solving equations with fractions http: mathhomeworkanswers.org ask# function of x calculus slope of a line through 2 points algebraic expressions solving equations with variables on both sides college algebra domain of a function solving systems of equations by elimination differential equation algebra word problems distributive property solving quadratic equations perimeter of a rectangle trinomial factoring factors of a number fraction word problems slope of a line limit of a function greater than or less than geometry division fractions how to find x intercept differentiation exponents 8th grade math simplifying fractions geometry 10th grade equivalent fractions inverse function area of a triangle elimination method story problems standard deviation integral ratios simplify systems of equations containing three variables width of a rectangle percentages area of a circle circumference of a circle place value solving triangles parallel lines mathematical proofs solving linear equations 5th grade math mixed numbers to improper fractions scientific notation problems quadratic functions number of sides of a polygon length of a rectangle statistics zeros of a function prime factorization percents algebra 1 evaluating functions derivative of a function equation area of a rectangle lowest common denominator solving systems of equations by graphing integers algebra 2 diameter of a circle dividing polynomials vertex of a parabola calculus problem perpendicular lines combining like terms complex numbers geometry word problems converting fractions to decimals finding the nth term range of a function 4th grade math greatest to least ordered pairs functions radius of a circle least common denominator slope unit conversion solve for y calculators solving radical equations calculate distance between two points area word problems equation of a tangent line multiplying fractions chemistry binomial expansion place values absolute value round to the nearest tenth common denominator sets set builder notation please help me to answer this step by step significant figures simplifying radicals arithmetic sequences median age problem trigonometry graphing derivatives number patterns adding fractions radicals midpoint of a line roots of polynomials product of two consecutive numbers limits decimals compound interest please help pre-algebra problems divisibility rules graphing functions subtracting fractions angles numbers discrete mathematics volume of a cylinder simultaneous equations integration probability of an event comparing decimals factor by grouping vectors percentage expanded forms rational irrational numbers improper fractions to mixed numbers algebra1 matrices logarithms how to complete the square mean statistics problem analytic geometry geometry problem rounding decimals 5th grade math problems solving equations with variables solving quadratic equations by completing the square simplifying trigonometric equation using identities
87,441 questions
99,039 answers
2,422 comments
16,939 users