bsc

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

commit 3f0a877b48ffcf71d451fb3c183603e0400ed316
parent 6a81b7df7e0ee5c8a6e09ee85433bf973db2e05a
Author: Amit Dutta <amitdutta4255@gmail.com>
Date:   Mon,  8 Dec 2025 21:13:43 +0530

[2025-12-08] assignment/assignment12.c: Cleaned up limits.h dependency

Diffstat:
Massignment/assignment12.c | 31+++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/assignment/assignment12.c b/assignment/assignment12.c @@ -1,39 +1,46 @@ -/* Write a C program that takes multiple integers as command-line arguments and finds the +/* Write a C program that takes multiple integers as command-line arguments and finds the maximum and minimum value among them. */ #include <stdio.h> #include <stdlib.h> -#include <limits.h> -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ int current_val, max_val, min_val, i; char *endptr; - if (argc < 2) { + long first_arg_val; + if (argc < 2) + { printf("Usage: %s <integer1> <integer2> ...\n", argv[0]); - return 1; + return 1; } - long first_arg_val = strtol(argv[1], &endptr, 10); - if (*endptr != '\0' || argv[1] == endptr) { + first_arg_val = strtol(argv[1], &endptr, 10); + if (*endptr != '\0' || argv[1] == endptr) + { printf("Error: Argument '%s' is not a valid integer.\n", argv[1]); return 1; } max_val = (int)first_arg_val; min_val = (int)first_arg_val; - for (i = 2; i < argc; i++) { + for (i = 2; i < argc; i++) + { long val = strtol(argv[i], &endptr, 10); - if (*endptr != '\0' || argv[i] == endptr) { + if (*endptr != '\0' || argv[i] == endptr) + { printf("Error: Argument '%s' is not a valid integer.\n", argv[i]); return 1; } current_val = (int)val; - if (current_val > max_val) { + if (current_val > max_val) + { max_val = current_val; } - if (current_val < min_val) { + if (current_val < min_val) + { min_val = current_val; } } printf("The maximum value is: %d\n", max_val); printf("The minimum value is: %d\n", min_val); - return 0; + return 0; } \ No newline at end of file
© 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