bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

luc033.c (1440B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /* Write a program to find the range of a set of numbers entered
      8 through the keyboard. Range is the difference between the smallest
      9 and biggest number in the list. */
     10 /* Let Us C, Chap- 5, Page - 87, Qn No.: B(f) */
     11 
     12 #include <stdio.h>
     13 int main()
     14 {
     15     int choice = 1, set_of_numbers[30], num, index = -1;
     16     while (choice == 1)
     17     {
     18         printf("\nEnter the number (Type any character and press Enter to finish.) : ");
     19         choice = scanf("%d", &num); // Checking whether the user has input any characters
     20         if (choice != 1)
     21         {
     22             // If the user inputs any characters, then choice = 0, it means he doesn't want to give any more input;
     23             choice = 0;
     24             printf("\nCharacter received. Stopping input...\n");
     25             break;
     26         }
     27         index++;
     28         set_of_numbers[index] = num;
     29     }
     30     int max = set_of_numbers[0], min = set_of_numbers[0];
     31     while (index >= 0)
     32     {
     33         if (max < set_of_numbers[index])
     34             max = set_of_numbers[index];
     35         if (min > set_of_numbers[index])
     36             min = set_of_numbers[index];
     37         index--;
     38     }
     39     int range = max - min;
     40     printf("\nBiggest number in the set  : %d", max);
     41     printf("\nSmallest number in the set : %d", min);
     42     printf("\nRange : %d", range);
     43     return 0;
     44 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror