Question

In: Computer Science

I'm having trouble determining the lines of code for 4-6 #include <stdio.h> //function prototypes void initializeArray(int...

I'm having trouble determining the lines of code for 4-6

#include <stdio.h>

//function prototypes
void initializeArray(int size, int ids[]);
void printArray(int size, int * idPointer);


int main(void) {
// 1. declare an array of 5 integers called ids
int ids[1,2,3,4,5];
  
// 2. declare an integer pointer called arrayPointer and
// initialize it to point to the array called ids
int *arrayPointer = ids;


// 3. call initializeArray() function sending to it
// 5 for the size and the array called ids
intializeArray(5,ids[]);
  
  
  
// 4. add 3 to the value at where arrayPointer is pointing to
*(arrayPointer + 3);


// 5. add 5 to the value at 2 locations past
// where arrayPointer is pointing to

  
  
// 6. call printArray() function sending to it
// 5 for the size and arrayPointer

  
  
return 0;
}


// This function initializes an array ids of size "size"
void initializeArray(int size, int ids[]) {
int i;
for (i = 0; i < size; i++) {
ids[i] = i * 100;
}
}


// This function prints an array of size "size". The array is pointed at by idPointer
void printArray(int size, int * idPointer) {
int i;
for (i = 0; i < size; i++) {
// 7. finish the code for the printf() statement
printf("Element at index %d is %d\n", i);
}
}

Solutions

Expert Solution

#include <stdio.h>

//function prototypes
void initializeArray(int size, int ids[]);
void printArray(int size, int * idPointer);


int main(void) {
// 1. declare an array of 5 integers called ids
int ids[5];
  
// 2. declare an integer pointer called arrayPointer and
// initialize it to point to the array called ids
int *arrayPointer = ids;


// 3. call initializeArray() function sending to it
// 5 for the size and the array called ids
initializeArray(5,ids);
  
  
// 4. add 3 to the value at where arrayPointer is pointing to
*(arrayPointer) += 3;


// 5. add 5 to the value at 2 locations past
// where arrayPointer is pointing to
*(arrayPointer+2) += 5;
  
  
// 6. call printArray() function sending to it
// 5 for the size and arrayPointer
printArray(5, arrayPointer);
  
  
return 0;
}


// This function initializes an array ids of size "size"
void initializeArray(int size, int ids[]) {
    int i;
    for (i = 0; i < size; i++) {
        ids[i] = i * 100;
    }
}


// This function prints an array of size "size". The array is pointed at by idPointer
void printArray(int size, int * idPointer) {
    int i;
    for (i = 0; i < size; i++) {
        // 7. finish the code for the printf() statement
        printf("Element at index %d is %d\n", i,*(idPointer+i));
    }
}


Related Solutions

I'm having trouble getting a certain output with this code #include <stdio.h> //function prototypes void initializeArray(int...
I'm having trouble getting a certain output with this code #include <stdio.h> //function prototypes void initializeArray(int size, int ids[]); void printArray(int size, int * idPointer); int main(void) { // 1. declare an array of 5 integers called ids int ids[5]; // 2. declare an integer pointer called arrayPointer and // initialize it to point to the array called ids int *arrayPointer = ids; // 3. call initializeArray() function sending to it // 5 for the size and the array called...
example_thread.c #include <stdio.h> #include <stdlib.h> #include <pthread.h> int shared= 0; void race(void); int main(){     pthread_t...
example_thread.c #include <stdio.h> #include <stdlib.h> #include <pthread.h> int shared= 0; void race(void); int main(){     pthread_t player1, player2, player3;     pthread_create(&player1, NULL, (void *)race, NULL);     pthread_create(&player2, NULL, (void *)race, NULL);     pthread_create(&player3, NULL, (void *)race, NULL);     pthread_join(player1, NULL);     pthread_join(player2, NULL);     pthread_join(player3, NULL);     printf("Total Number = %d\n", shared);     return 0; } void race(void) {     long i,tmp;     for(i=1; i<=200000; i++) {         tmp = shared;         tmp = tmp + 1;         shared =...
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x...
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x = 3;     i = fun(x);     printf("%d\n", i);     return 0; } int fun(int i) {      int res = 0;      res = pow (i , 3.0);      return ( res); }
please fix code #include <stdio.h> #include <stdlib.h> #include <string.h> // function declarations int getValidJerseyNumber(); int getValidRating();...
please fix code #include <stdio.h> #include <stdlib.h> #include <string.h> // function declarations int getValidJerseyNumber(); int getValidRating(); int main() { // declaring variables int size = 5; int jerseyNo[size]; int rating[size]; int i = 0, jno, rate; char option; /* Getting the inputs entered by the user * and populate the values into arrays */ for (i = 0; i < size; i++) { printf("Enter player %d's jersey number:", i + 1); jerseyNo[i] = getValidJerseyNumber(); printf("Enter player %d's rating:\n", i +...
What’s the output of following code fragment: #include<stdio.h> #include<signal.h> void response (int sig_no) { printf("25"); }...
What’s the output of following code fragment: #include<stdio.h> #include<signal.h> void response (int sig_no) { printf("25"); } void response2 (int sig_no) { printf("43"); }     int main() {      int id = getpid();      signal(SIGUSR1, response); signal(SIGKILL, response2); for(int i=0; i<4; i++) { sleep(1); if (i % 3 == 0) { kill(id, SIGUSR1); } else { kill(id, SIGKILL); } } return 0; }
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void main (void) { int m; double y; m=15; y=308.24; printf ("The value of m in main is m=%d\n\n",m); function1(); function2(m,y); printf ("The value of m is main still m = %d\n",m); } void function1(void) { printf("function1 is a void function that does not receive\n\\r values from main.\n\n"); } void function2(int n, double x) { int k,m; double z; k=2*n+2; m=5*n+37; z=4.0*x-58.4; printf ("function2 is...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void main (void) { int m; double y; m=15; y=308.24; printf ("The value of m in main is m=%d\n\n",m); function1(); function2(m,y); printf ("The value of m is main still m = %d\n",m); } void function1(void) { printf("function1 is a void function that does not receive\n\\r values from main.\n\n"); } void function2(int n, double x) { int k,m; double z; k=2*n+2; m=5*n+37; z=4.0*x-58.4; printf ("function2 is...
#include <stdio.h> int main(void) { int input = -1; double average = 0.0;    /* Use...
#include <stdio.h> int main(void) { int input = -1; double average = 0.0;    /* Use this for your input */ scanf("%d", &input);    /* This is the only output you need */ printf("%.1lf", average); return 0; } Please write a C coding program (make it simple coding)  that find the average of sequence integer. when user enter integers, once at a time. Also, If the user enters 0 (zero), the code will calculates the average and then prints it, and...
#define _CRT_SECURE_NO_WARNINGS // Put your code below: #include <stdio.h> int main(void) { int day, hightemp[10], lowtemp[10],...
#define _CRT_SECURE_NO_WARNINGS // Put your code below: #include <stdio.h> int main(void) { int day, hightemp[10], lowtemp[10], numbers, highesttemp, highestday, lowesttemp, lowestday, numbers2 = 0, hightotal = 0, lowtotal = 0, averageday = 0, numbers3; double averagetemp; printf("---=== IPC Temperature Calculator V2.0 ===---"); printf("\nPlease enter the number of days, between 3 and 10, inclusive: "); scanf("%d", &numbers); if (numbers < 3 || numbers > 10) { printf("\nInvalid entry, please enter a number between 3 and 10, inclusive: "); scanf("%d", &numbers); printf("\n");...
#include <stdio.h> const int DECK_SIZE = 52; int deck[DECK_SIZE]; int main(void) { /* Populate the deck...
#include <stdio.h> const int DECK_SIZE = 52; int deck[DECK_SIZE]; int main(void) { /* Populate the deck */ for(int i = 0; i < DECK_SIZE; i++) { deck[i] = i + 1; }    /* Get the cut position as an integer input */    /* Verify that the input is valid */    /* Cut the deck */    /* Print the resulting deck with one element on each line */ return 0; } Write a program that "cuts" a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT