assignment-p-12_v2.c (991B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 06 Feb 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Write a C program that takes multiple integers as command-line arguments and finds the 9 maximum and minimum value among them. */ 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 14 int main(int argc, char *argv[]) 15 { 16 int current_val, max_val, min_val, i; 17 if (argc < 2) 18 { 19 printf("Usage: %s <integer1> <integer2> ...\n", argv[0]); 20 return 1; 21 } 22 max_val = atoi(argv[1]); 23 min_val = atoi(argv[1]); 24 for (i = 2; i < argc; i++) 25 { 26 current_val = atoi(argv[i]); 27 28 if (current_val > max_val) 29 { 30 max_val = current_val; 31 } 32 if (current_val < min_val) 33 { 34 min_val = current_val; 35 } 36 } 37 printf("The maximum value is: %d\n", max_val); 38 printf("The minimum value is: %d\n", min_val); 39 return 0; 40 }