bsc

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

root / semester_1 / assignment-primary / assignment-p-12_v2.c

assignment-p-12_v2.c (800B)


      1 /* Write a C program that takes multiple integers as command-line arguments and finds the
      2 maximum and minimum value among them. */
      3 
      4 #include <stdio.h>
      5 #include <stdlib.h>
      6 
      7 int main(int argc, char *argv[])
      8 {
      9     int current_val, max_val, min_val, i;
     10     if (argc < 2)
     11     {
     12         printf("Usage: %s <integer1> <integer2> ...\n", argv[0]);
     13         return 1;
     14     }
     15     max_val = atoi(argv[1]);
     16     min_val = atoi(argv[1]);
     17     for (i = 2; i < argc; i++)
     18     {
     19         current_val = atoi(argv[i]);
     20 
     21         if (current_val > max_val)
     22         {
     23             max_val = current_val;
     24         }
     25         if (current_val < min_val)
     26         {
     27             min_val = current_val;
     28         }
     29     }
     30     printf("The maximum value is: %d\n", max_val);
     31     printf("The minimum value is: %d\n", min_val);
     32     return 0;
     33 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror