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

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) { float funds = 1.0, cost = 0.1; int candies = 0;...
#include <stdio.h> int main(void) { float funds = 1.0, cost = 0.1; int candies = 0; while(cost <= funds) { candies += 1; funds -= cost; cost += 0.1; } printf("%d candies with $%.2f left over.\n",candies,funds); return 0; } When you compile and run this code you get 3 candies with $0.40 left over. Without knowing how floating point numbers work in a computer, would this result be expected? Explain why or why not. Explain why this result, in fact,...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main(...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main( ) {                         for (int i=1; i<=2; i++)                                     printf("%d", fac(i)); } int fac(int x) {                         x = (x>1) ? x + fac(x-1) : 100);                         return x; }
#include <stdio.h> #define MAX 8 //Byte = 8 bits void func_and(int a[], int b[], int result[])...
#include <stdio.h> #define MAX 8 //Byte = 8 bits void func_and(int a[], int b[], int result[]) { for(int i=0; i < MAX; i = i + 1){ result[i] = a[i] & b[i]; } } void func_or(int a[], int b[], int result[]) { for(int i=0; i < MAX; i = i + 1){ result[i] = a[i] || b[i]; } } void func_not(int a[], int result[]) { for (int i = 0; i < MAX; i = i + 1) { result[i]...
My current code that is not working correctly #include<stdio.h> #include<math.h> int main() { //variable declaration int...
My current code that is not working correctly #include<stdio.h> #include<math.h> int main() { //variable declaration int a,b,c,D,n; double x1,x2; double realPart, imagPart; do { // this set of code blocks prompts a message to the user and then read the integer entered and stores it as an integer printf("Enter a value for a:\n"); scanf("%d",&a); printf("Enter a value for b:\n"); scanf("%d",&b); printf("Enter a value for c:\n"); scanf("%d",&c); printf("You entered the Equation \n"); printf("%dx^2%+dx%+d=0\n",a,b,c); D = b*b - 4*a*c;    if (D<0)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT