Question

Linux C language User entered integers as command line arguments forexample ./compare 27 13 15 Find...

Linux C language

User entered integers as command line arguments

forexample

./compare 27 13 15

Find the smallest and largest numbers, which you can do either by allocating an array and converting the strings to numbers or by converting them as you do the comparison. Then output the result. For example:

The smallest integer was: 13

The largest integer was: 27

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
    int min = 0, max = 0, i, n;
    for (i = 1; i < argc; ++i) {
        n = atoi(argv[i]);
        if (i == 1) {
            min = n;
            max = n;
        }
        if (n > max)
            max = n;
        if (n < min)
            min = n;
    }
    printf("The smallest integer was: %d\n", min);
    printf("The largest integer was: %d\n", max);
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Linux C language User entered integers as command line arguments forexample ./compare 27 13 15 Find...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that finds either the largest or smallest of the ten numbers as command-line...

    Write a program that finds either the largest or smallest of the ten numbers as command-line arguments. With –l for largest and –s for smallest number, if the user enters an invalid option, the program should display an error message. Example runs of the program: ./find_largest_smallest –l 5 2 92 424 53 42 8 12 23 41 output: The largest number is 424    ./find_largest_smallest –s 5 2 92 424 53 42 8 12 23 41 output: The smallest number is...

  • You are required to develop a simple Linux shell in C language “shell.c". The shell has...

    You are required to develop a simple Linux shell in C language “shell.c". The shell has to perform the following requirements: - - The shell prompt is “"myshell>". - Run commands either from current directory or from “/bin" directory using the "exec" system call. - Support output redirection like "command> filename" using "dup" system call. Note: save the output of the comment in the (filename). - Implement the “history shell command to list the last ten commands entered so far....

  • Please solve this C language progrm (2-D Array program) the most basic way ! Thank You!...

    Please solve this C language progrm (2-D Array program) the most basic way ! Thank You! Write a function that takes a 4 x 4 array of integers as its parameter. The function must use two nested for-loops to determine the largest integer in the array as well as its row and column numbers. Recall that C-functions cannot return multiple values. Use pointers in the function parameter list to relay the results to the caller program. Write another function, which...

  • This is being done in c using command line in Linux 1.1 llist: Linked list Write...

    This is being done in c using command line in Linux 1.1 llist: Linked list Write a program llist that maintains and manipulates a sorted linked list of integers according to instructions received from standard inpu. The linked list is maintained in order, meaning that each integer will be larger than the one preceeding it. 1list maintains a linked list containing zero or more integers, ordered from least to greatest llist will need to allocate space for new nodes as...

  • ​​​​​​ C Programming Language The operation of multiplication for positive integers can be expressed as: A.B=2...

    ​​​​​​ C Programming Language The operation of multiplication for positive integers can be expressed as: A.B=2 1 A for (A+[A.(B-1)] B=1 for B>1 Task 1 (for 1 point) is to write a program that will read and print on the screen the values of two integers (A and B) given by user as command line parameters. Task 2 (for 1 point) is to write a program that will calculate the result of the multiplication of two integers. It should print...

  • Write a computer program that prompts the user for one number, n for the number of...

    Write a computer program that prompts the user for one number, n for the number of items in the array to sort, and create and sort 1000 different arrays of this size timing the run to get an average time to sort an array of this size. Then do the following: Initiate a variable running_time to 0 Create a for loop that iterates 1000 times. In the body of the loop, Create an array of n random integers (Make sure...

  • Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive...

    Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions) Functions you need to implement: Define function initialize() that takes array lotterNumbers[] as a parameter and assigns...

  • Language: C# In this assignment we are going to convert weight and height. So, the user...

    Language: C# In this assignment we are going to convert weight and height. So, the user will have the ability to convert either weight or height and as many times as they want. There conversions will only be one way. By that I mean that you will only convert Pounds to Kilograms and Feet and Inches to Centimeters. NOT the other direction (i.e. to Pounds). There will be 3 options that do the conversion, one for each type of loop....

  • Please write a C++ program that will accept 3 integer numbers from the user, and output...

    Please write a C++ program that will accept 3 integer numbers from the user, and output these 3 numbers in order, the sum, and the average of these 3 numbers. You must stop your program when the first number from the user is -7. Design Specifications: (1) You must use your full name on your output statements. (2) You must specify 3 prototypes in your program as follows: int max(int, int, int); // prototype to return maximum of 3 integers...

  • C++ pleasr Extra Credit: Large Integer (25 points) In C++, the largest int value is 2147483647....

    C++ pleasr Extra Credit: Large Integer (25 points) In C++, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an array. Write a program that inputs two positive integers of, at most,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT