How do you calculate the range of numbers using C?
How do you calculate the range of numbers using C?
I want to write a program that displays the lowest number to highest number from a set of numbers that was entered.
that wasn't so bad, now was it?Code:get the numbers min = first number while there are more numbers to be checked { if the next number is lower than min set min to the next number } max = first number while there are more numbers to be checked { if the next number is higher than max set max to the next number }
If I had a world of my own, everything would be nonsense. Nothing would be what it is, because everything would be what it isn't. And contrariwise, what it is, it wouldn't be, and what it wouldn't be, it would. You see?
>How do you calculate the range of numbers using C?
Simple enough, just take the range and then print the lowest to the highest.
-PreludeCode:#include <stdio.h> #include <stdlib.h> static void range ( int low, int high, FILE *out ) { while ( low <= high ) { fprintf ( out, "%d ", low++ ); fflush ( out ); } } int main ( void ) { int low, high; printf ( "Enter a range of numbers (ex. 3-12): " ); fflush ( stdout ); if ( scanf ( "%d %*c %d", &low, &high ) != 2 ) { fprintf ( stderr, "Invalid input\n" ); exit ( EXIT_FAILURE ); } range ( low, high, stdout ); return EXIT_SUCCESS; }
My best code is written with the delete key.