A programmer that you work with, Peter, is a jerk. He is responsible for an array that is a key part of an important program and he maintains a sum of the array value.He won't give you access to this array; however, your boss has told you that you need to get input from the user and then place it into the array.Each evening Peter will scan the code and remove any illegal references to his array.
Using pointers, access Peter's array without him knowing it and place three values that you got from the user at locations 3, 6, and 9. Recalculate the sum value and update it.
STARTER CODE BELOW:
#include <stdio.h>
#include
<stdlib.h>
int main(){
int petersArray[10] = {100,200,300,400,500,600,700,800,900,1000}; i
int petersArraySum = 0;
printf("Peter's Array:\n");
for (int loop = 0; loop < 10; loop++) {
printf("%d ",petersArray[loop]);
petersArraySum += petersArray[loop];
}
printf("\n");
printf("Peter's Array Sum: %d\n\n",petersArraySum);
return 0;
}
#include <stdio.h>
#include<stdlib.h>
int main()
{
//array declaration
int petersArray[10];
int petersArraySum = 0;
//get user input
printf("Enter Array:\n");
for (int loop = 0; loop < 10; loop++)
{
scanf("%d", (petersArray+loop));
if((loop+1)%3==0)
petersArraySum += *(petersArray+loop);
}
//dispaly the result
printf("\n");
printf("Peter's Array Sum: %d\n\n",petersArraySum);
return 0;
}
OUTPUT:
Enter Array:
10
20
30
40
50
60
70
80
90
100
Peter's Array Sum: 180
Get Answers For Free
Most questions answered within 1 hours.