Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this C program, you will take command-line arguments of 10 numbers, which are assumed to be integers, and find the median or the average

image text in transcribed

In this C program, you will take command-line arguments of 10 numbers, which are assumed to be integers, and find the median or the average of them. The average of the array should be a floating point number (double). Before the numbers on the command line, there will be an argument that indicates whether to find the median (- m) or average (-a), if the user entered an invalid option or incorrect number of arguments, the program should display an error message. To find the median of an array, use the selection_sort function provided above to sort the array, the median is the number that is halfway into the array: a[n/2], where n is the number of the elements in array a.

input and output:

./a.out a 2 6 8 4 9 10 7 3 11 5

output: 6.5

./a.out m 2 6 8 4 9 10 7 3 11 5

output: 7

./a.out

output: usage: ./a.out option (a or m) followed by 10 numbers

./a.out d 2 6 8 4 9 10 7 3 11 5

output: Invalid option

1) Name the program command_line.c

2) Use strcmp function to process the first command line argument.

3) Use atoi function in to convert a string to integer form.

1 selection sort.c, project 6, Program Design 4 #include 5 #define N 10 7 void selection sort (int ai, int n); 9 int main (void) 10 11 int i; 12 int a[N] 13 14 printf( "Enter %d numbers to be sorted. ", N); 15 for (i=0;i a [largest]) largest 1; temp = a [n-1); a [n-1] a [largest]; a [largest] = temp ; 43 45 selection_sort (a, n -1): 46h<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions