Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/* Enter size of array (cannot be negative integer), and then ask for array elem

ID: 3629196 • Letter: #

Question

/* Enter size of array (cannot be negative integer), and then ask for array elements */


#include<stdio.h>

#define MAXNUMBER 100

int printAll()
{
int s;
for(s = 0; s<size; s++)
{
printf("%d",myArray[s] + " ");
}
return 0;
}

int main()
{
char *a = "Negative integer, bye!";
int size,counter,i;
int myArray[MAXNUMBER];
counter = 0;
printf("Enter size of array or enter negetive int to quit ");
scanf("%d", &size);
if(size<0)
{
printf(a);
return 0;
}
printf("Enter elements of array, cannot be negative int ");
while(counter<size)
{
scanf("%d",&i);
if(i<0)
{
printAll();
break;
}
myArray[counter] = i;
counter++;
}
printAll();
return 0;
}



Explanation / Answer

please rate - thanks

it gets call twice. it just had errors.

I wasn't sure what it was supposed to print when the input was negative

/* Enter size of array (cannot be negative integer), and then ask for array elements */


#include<stdio.h>
#include <conio.h>
#define MAXNUMBER 100

int printAll(int myArray[],int size)
{
int s;
for(s = 0; s<size; s++)
{
printf("%d ",myArray[s]);
}
printf(" ");
return 0;
}

int main()
{
char *a = "Negative integer, bye!";
int size,counter,i;
int myArray[MAXNUMBER];
counter = 0;
printf("Enter size of array or enter negetive int to quit ");
scanf("%d", &size);
if(size<0)
{
printf(a);
return 0;
}
printf("Enter elements of array, cannot be negative int ");
while(counter<size)
{
scanf("%d",&i);
if(i<0)
{
printAll(myArray,size);
break;
}
myArray[counter] = i;
counter++;
}
printAll(myArray,size);
getch();
return 0;
}