Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Exercise: Write the following program (saved as sumex.c). It must compile successfully using: gcc --std=c99 sumex.c -o sumex It will take whole numbers as

The Exercise:

Write the following program (saved as sumex.c). It must compile successfully using: gcc --std=c99 sumex.c -o sumex It will take whole numbers as command line arguments. It will add them up and print out the total and maximum values (space separated). It should return 0 on success and 1 if not enough arguments are given. If an argument is not a whole number, then treat it as 0. eg: ./sumex -2 4 1 Would output: 3 4

I have the following program which doesn't work. Please help as I do not know where I have gone wrong.

#include #include

/* return sum of numbers */

int total(int a, int b, int c) { int sum; sum = a + b + c; return sum; }

/* checks maximum of numbers */ int max(int a, int b, int c) { if (a > b && a > c) { return a; } else if (b > a && b > c) { return b; } else { return c; } return 0; }

/* taking argument as command line */ int main(int argc, const char* argv[]) { int a, b, c;

int sumnum; int maximum;

/* convert a1, b1, c1 to integer */

int a1 = atoi(argv[1]);

int b1 = atoi(argv[2]);

int c1 = atoi(argv[3]);

/* checking whether the number of arguments passed * is less than 4 (including argv[0]) */

if (argc

sumnum = total(a, b, c); maximum = max(a, b, c); /* print out the sum of numbers and max number * return 0 if successful */ printf("%d %d ", sumnum, maximum); return 0; }

OUTPUT:

image text in transcribed

S gccstd c99 sumex.c -o sumex $./sumex 3 4 5 1237059664 4195440

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

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago