Question

Given the following code snippet, what is this program calculating? for (int i = 0; i...

Given the following code snippet, what is this program calculating?

for (int i = 0; i < n; i++) {
    sum += arr[i];
}
sum /= n;

Homework Answers

Answer #1

Answer is : Your code will calculate Average of Array elements

Proof:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create three address code from the program snippet below. int a = 2, b = 8,...
Create three address code from the program snippet below. int a = 2, b = 8, c = 4, d; for (j = 0; j <= 10; j ++) ( a = a * (j * (b / c)); d = a * (j * (b / c)); }
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i];...
Consider the following function: double arrayavg(int a[], int n){ int sum=0; for(int i=0; i!=n; ++i){ sum+=a[i]; } return (double)sum/n; } Rewrite the function to eliminate the array subscripting (a[i]), using pointer arithmatic instead. Write a program that reads a line of input and checks if it is a palindrome (ignoring spaces) Write a program that takes the name of a file as a command line argument, and prints the contents of the file (similar to the linux 'cat' program). Write...
Given the following code: int x = 0; int y = 10; int *ptr = &x;...
Given the following code: int x = 0; int y = 10; int *ptr = &x; *ptr = -55; x += -52; ptr = &y; *ptr += 52; printf("%d\n", x); What is printed to the screen?
Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num ==...
Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num == 0) return 0; else if (num > 100) return -1; else     return num + tq( num – 1 ); } Group of answer choices: 0 4 -1 10 Q2: Given that values is of type LLNode<Integer> and references a linked list (non-empty) of Integer objects, what does the following code do if invoked as mystery(values)? int mystery(LLNode<Integer> list) {    if (list.getLink() ==...
int main() { int item; inti; //cout << arr[i] << ";"; cin >> item; int *arr...
int main() { int item; inti; //cout << arr[i] << ";"; cin >> item; int *arr = new int[item]; // for (int x = 0; x < item; x++) // { // } for (int x = 0; x < item; x++) { cin >> arr[x]; if (x > 0) { InsertionSort(x + 1, arr); for (inti = 0; i < x + 1; i++) { cout << arr[i] << ";"; }cout << endl; } } return 0; } can...
Here is a “snippet,” a few lines, taken from a C language program. int a, b,...
Here is a “snippet,” a few lines, taken from a C language program. int a, b, c; float d, e, f; c = a + b; d = e + f; How many distinct opcodes will appear in the machine code compiled from this C snippet and why?
Convert the following C program to inline assembly int main(){ int i; printf("Hex Dec Oct Ch\n");...
Convert the following C program to inline assembly int main(){ int i; printf("Hex Dec Oct Ch\n"); for (i = 32; i < 256; i++){ printf("%2x %3d %3o %c\n",i,i,i,i); } return 0; } the code below shows where to do the assembly at: int main(){ int i = 0; char *hdr = "Hex Dec Oct Ch\n"; char *msg = " %2x %3d %3o %c\n"; printf("%s\n",hdr); ———asm{ // DO ASSEMBLY HERE } system("pause"); }
The following code generates a list arr with 100 items. import random random.seed(0) arr = [...
The following code generates a list arr with 100 items. import random random.seed(0) arr = [ random.randint(1,100) for _ in range(100) ] Write a program that computes the sum of squares of all the numbers in the list arr Submit both the code and result (sum of squares of all the numbers in arr)
Analyze the worst case running time of the following code in “big-Oh” notation in terms of...
Analyze the worst case running time of the following code in “big-Oh” notation in terms of the variable n. a. void fdisp1(int n) { for(int i=0; i < n; i++) { for(int j=0; j < n; j++) { for(int k=0; k < n; k++) { for(int m=0; m < n; m++) { System.out.println("Hi I am Here"); } } } } } b. voidprintAllPossibleOrderedPairs(intarr[], int size) { for (int i = 0; i < size; i++) { for (int j =...
1. public int add100(int[] array) { if (array.length < 100) { return 0; } int sum...
1. public int add100(int[] array) { if (array.length < 100) { return 0; } int sum = 0; for (int i = 0; i < 100; i++) { sum += array[i]; } return sum; } 2. int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { sum++; sum++; } } for (int i = 0; i < n; i += 2) { sum++; } 3. nt...