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 2
1) Name your program numbers.c.
2) Use atoi function in <stdlib.h> to convert a string to integer form.
3) Generate the executable as find_largest_smallest.
gcc –Wall –o find_largest_smallest numbers.c
int main() {
int a[30], i, num, smallest,largest;
char f;
printf("\nEnter no of elements :");
scanf("%d", &num);
printf("\nEnter elements :\n");
//Read n elements in an array
for (i = 0; i < num; i++)
scanf("%d", &a[i]);
for (i = 0; i < num ; i++){
if (largest < a[i])
largest = a[i];
}
//Consider first element as smallest
smallest = a[0];
for (i = 0; i < num; i++) {
if (a[i] < smallest) {
smallest = a[i];
}
}
printf("Enter 'l' for largest number or 's' for smallest number
\n");
scanf("%s",&f);
if(f == 'l')
printf("\nThe Largest number is %d", largest);
else if(f == 's')
printf("\nThe smallest number is %d", smallest);
else
printf("error\n");
return (0);
}
Output:

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 numbersas command-line arguments. With –l for largest and –s for smallest number, if the userenters 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 41output: The largest number is 424 ./find_largest_smallest –s 5 2 92 424 53 42 8 12 23 41output: The smallest number is 2 1) Name your program...
3. (c-program) Write a program that finds the largest and smallest value in a series of numbers entered by a user. The user must enter 25 values. Note if that if the user enters "0" they must correct and add another number. Print out the original entered values, the largest number, the smallest number. Note whether the user tried to enter "O".
In C Programming Adding to your program in part A, go through the command line arguments and find the largest and smallest arguments by alphabetical order. Note that you should not need to sort your arguments, but instead compare them and save the smallest and largest strings as you go through. For example, if called with ./reverse one two three: It would display the output for part A: Three two one And then it would display The smallest string was:...
Write a program in C++ language that finds the largest number in an array of positive numbers using recursion. Your program should have a function called array_max that should pass in an int array, and an int for the size of the array, respectively, and should return an int value. As an example, given an array of size 10 with contents: {10, 9, 6, 1, 2, 4, 16, 8, 7, 5} The output should be: The largest number in the...
Write a full program that will accept any number of command line arguments and print them to the screen. Suppose your program is called Print.java. When the command java Print hello goodbye you is run, the output will be hello goodbye you Write a full program that will accept exactly three command line arguments that can be interpreted as integers, and will add them up. If there aren't exactly 3 command line arguments, print an error message and terminate the program....
Your task is to write a C++ program that consumes integer values as command line arguments and returns the arithmetic mean of these values. To increase the flexibility of the program, there should be no set number of arguments. To overcome this, we will require the argument argv[1] to be the number of integers the user enters. For example, if the user wants to calculate the arithmetic mean of 4 numbers, they would pass in 4 as the first argument...
Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...
Problem: Write a program that behaves as described below.If the first command-line argument after the program name (argv[1]) is “--help”, print the usage information for the program. If that argument is not “--help”, you are to expectargv[1]and subsequent arguments to be real numbers(C, integer, float, or double types)in formats acceptable to the sscanf()function of the C library or strings of ASCII chars that are not readable as real numbers. You are to read the numbers, count them and calculate the...
Write a python program that runs only on the command-line prompt. i.e. if you run this program on IDEL it would give you an error message. Name the program “buy.py.” Assume that this program is used by a departmental store to calculate your total price if you want to buy an extended warranty for your purchased Computer. The program takes two arguments at the command-line prompt: 1) the computer’s brand name, and 2) the price of the computer that you...
Write a full program that will accept exactly three command line arguments that can be interpreted as integers, and will add them up. If there aren't exactly 3 command line arguments, print an error message and terminate the program. Suppose your program is called Add.java. Then running the command java Add 1 2 3 will output 6, and running java Add, for example, will cause the program to shut down. Consider the following recursive method: public static int mystery (int n)...