Question

In: Computer Science

A programmer that you work with, Peter, is a jerk. He is responsible for an array...

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 ONLY AT POSITIONS 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;

Solutions

Expert Solution

Code.

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

void printArrayandGetSum(int a[])
{
    int petersArraySum=0;
    printf("Peter's Array:\n");
    for (int loop = 0; loop < 10; loop++) {
        printf("%d ",a[loop]);
        petersArraySum += a[loop];
    }
    printf("\n");
    printf("Peter's Array Sum: %d\n",petersArraySum);
}

int main(){
int petersArray[10] = {100,200,300,400,500,600,700,800,900,1000}; 
int petersArraySum = 0;

printArrayandGetSum(petersArray);
printf("\n");
int n1,n2,n3;

printf("Enter 3 numbers to be placed: ");
scanf("%d%d%d", &n1,&n2,&n3);
*(petersArray+2)=n1;
*(petersArray+5)=n2;
*(petersArray+8)=n3;
printArrayandGetSum(petersArray);

return 0;
}

Output:

Please comment in case of doubts or queries.
It would be really helpful if you could upvote :)


Related Solutions

Peter lives for three periods. He is currently considering three alternative education-work options. He can start...
Peter lives for three periods. He is currently considering three alternative education-work options. He can start working immediately and earn $100,000 in period 1, $110,000 in period 2, and $90,000 in period 3. Alternatively, he can spend $50,000 to attend college in period 1 and then earn $180,000 in period 2 and 3. Finally, he can receive a doctorate degree in period 2 after completing his college education in period 1. This last option will cost him nothing in period...
You work as a Corporate Risk Analyst at JP Morgan. You clients Peter and Angela are...
You work as a Corporate Risk Analyst at JP Morgan. You clients Peter and Angela are planning to start a new company and have come to you for advice. Angela is worried that company’s managers may serve their own personal interests rather than maximizing the revenues of the company. Explain to Angela what this problem is called and prescribe one way of dealing with this problem. Angela is unsure about the appropriate mix of debt and equity for the new...
Pretend you work as a computer programmer. Write a memo to your department convincing them to...
Pretend you work as a computer programmer. Write a memo to your department convincing them to donate to a non-profit of your choosing. Include all details for donation (think Who, What, When Where Why, How). Include the following sections: Header (company letterhead, to, from, date, subject,), Salutation, Opening paragraph, middle paragraph(s), closing paragraph, complimentary closing, and signature. Paraphrase information about the nonprofit in your middle paragraphs, and cite this info in APA formatting. 2 pages max. U.5
Peter and Mary take turns rolling a fair die. If Peter rolls 1 or 2 he...
Peter and Mary take turns rolling a fair die. If Peter rolls 1 or 2 he wins and the game stops. If Mary rolls 3, 4, 5, or 6, she wins and the game stops. They keep rolling in turn until one of them wins. Suppose Peter rolls first. (a) What is the probability that Peter wins? (b) What is the probability that Mary wins?
You work for the Colorado Chapter of the Mutual UFO Network (MUFON) that is responsible for...
You work for the Colorado Chapter of the Mutual UFO Network (MUFON) that is responsible for compiling all UFO sightings in the US. You are interested in whether there is a difference between rural and urban people in the mean number of UFOs they have ever seen. You randomly sample 200 urban and 150 rural Coloradoans and ask how many UFOs they’ve seen. Of the urbanites, the mean number of UFOs is 1.3 UFOs with a standard deviation of .4....
Question: Peter is the sole owner of a T-Shirt Shop.  He has provided you with the following...
Question: Peter is the sole owner of a T-Shirt Shop.  He has provided you with the following information in relation to the 2018 budget:- Estimated sales units for the year                                                                         40,000 Selling price per unit                                                                                                   $30 Estimated total sales                                                                                      $1,200,000 Based on the above sales units and dollars, the following expenses are expected to be incurred annually:- Cost of Goods Sold (@ $12 per unit)                                                                 $480,000 Rent of Premises (75% Shop, 25% Office)                                                           $44,040 Salaries – Sales Staff                                                                                          $168,000 Salaries – Office Staff                                                                                           $80,400 Delivery Expenses (@$1.25 per...
Programmer defined Function / Arrays: 1.Write a function for printing an array. void print_array (int arr[],...
Programmer defined Function / Arrays: 1.Write a function for printing an array. void print_array (int arr[], int size); 2. Write a function to generate an array of random integers. void random_array (int arr[], int size, int range); The scale of numbers should be 1 to range. 3. Write a function to find the sum of a sequence of number. int sum (int arr[], int size); 4. Write a function rotate(arr[], d, n) that rotates arr[] of size n by d...
BOXPLOTS AND WHISKERS Scenario: You work for the Medical Center's retail division. This division is responsible...
BOXPLOTS AND WHISKERS Scenario: You work for the Medical Center's retail division. This division is responsible for managing the   sales and rentals of products from the gift shops, cafes, cafetrias, and medical equipment rentals. You've been asked by the Director to undertake initiatives to boost sales at the gift shops. You've worked with the Marketing Department to produce a couple of posters to strategically place throughout the system. You're expected to create a boxplot & whiskers diagram for each scenario...
Joey Joystick is a computer programmer. While he was in his final year of university studies,...
Joey Joystick is a computer programmer. While he was in his final year of university studies, he worked as an intern with a local electronic games producer, Great Games Pty Ltd. Joey impressed his supervisors with his insightful comments and other input on design work. They were so impressed with his work on one design, Crypt Force, that they gave him part credit for it and paid him a general bonus for it. Crypt Force ultimately won an industry award...
You work for Johnson Brothers Baked Treats. You are responsible for managing ingredient inventory, including butter,...
You work for Johnson Brothers Baked Treats. You are responsible for managing ingredient inventory, including butter, milk, eggs, flour, and all the other materials that go into your company's baked products. Storing these materials can get expensive so you want to be efficient in your ordering, having just enough on hand at any given time without risking of running out. Which method of inventory control do you think will work best at Johnson Brothers? a. Have two days' worth of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT