Table processing and pointers

SoccerBoss
Category:
Programming
Price: $10 USD

Question description

The C program below receives integers as command line arguments. After receiving the required values, the program calls the subroutine "calculate_and_print" which receives an array and its size passed by the main program, prints the numbers on the screen and prints their sum on the screen.


#include <stdio.h> 
#include <stdlib.h>

void calculate_and_print(int *, int);

int main(int argc, char *argv[])
{
 int x, sum=0, size=5, array[5];
 if(argc == 6){ 
 /* Program name and command line parameters */
 for(x=0;x<argc-1;x++){
 array[x] = atoi(argv[x+1]);
 }
 calculate_and_print(array, size);
 }else{
 printf("Incorrect number of command line arguments\n");
 }
 return 0;
}

Your task is to write the subroutine "calculate_and_print". The example printout shows how to print the numbers. The main program includes things that are outside the scope of this course, but you only need to write a subroutine that serves the main program.

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: Cornell University
PREMIUM TUTOR
Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1831 tutors are online

Related Programming questions

11/09/2013
11/09/2013
11/09/2013
11/09/2013
11/09/2013
11/09/2013
11/09/2013
11/09/2013

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors