Question

20) What is the output of the following segment of C code: int avg(int n, int*...

20)

What is the output of the following segment of C code:

int avg(int n, int* a);

int main () {

            int array[4]={1,0,6,9};

            printf("%d", avg(4, array)+ 1);

            system("pause");

            return 0;

}

int avg(int n, int* a) {

int i, sum=0;

for (i=0;i<n;i++) {

sum+=a[i];

}

return sum/n;

}

  1. a) 16
  2. b) 5
  3. c) 4
  4. d) 8

21)

What is the output of the following segment of C code:

int x = 2;

int y = 3;

do {

switch (x) {

            case -1:           y+=2;

                                    x=3;

                                    break;

            case 1:            x--;

                                    y++;

            case 2:            x--;

                                    y--;

            case 3:            break;

            default:            x = y;

            }

} while (x != 3);

printf("%d", y);

a) 2

b) 3

c) 5

d) 4

22)

What is the output of the following segment of C code:

int x=3, y=2, z=4;

while (x!=y) {

if (x>y && z > y) {

x--;

y=z+1;

} else if (z < y) {

z=y;

} else y--;

}

printf("%d", z);

a) 4

b) 5

c) 3

d) 6

23)

What is the output of the following segment of C code:

int a =4;

int b=2;

a=pow(a,b);

printf(“%d”, a);

a) 18

b) 16

c) 6

d) 8

0 0
Add a comment Improve this question Transcribed image text
Answer #1

20)

5

Explanation:- the method return avg of array that is 4 and print 4+1=5

21)2

22) a) 4

23)b 16

Add a comment
Know the answer?
Add Answer to:
20) What is the output of the following segment of C code: int avg(int n, int*...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • should be in C language What is the output of the following segment of C code:...

    should be in C language What is the output of the following segment of C code: void CapsLetter (char* x, charl); int main() { char* text; text="This is some sample text."; CapsLetter(text, 'e'); printf("%s", text); return 0; سی void Caps Letter (char* x, char 1) { int i=0; while (x[i]!='\0') { if (x[i]==1) x[i]=1-32; } 1. This is som sample text. 2. THIS IS SOME SAMPLE TEXT. 3. This is some sample text. 4. this is some sample text. What...

  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

  • 31. The following code segment is syntactically correct:              int number{20};          cout << number <<...

    31. The following code segment is syntactically correct:              int number{20};          cout << number << setbase(16) << " " << number                               << setbase(10) << " " << number                                 << showpos << " " << number << endl;                 T__   F__       32. The following statement wants to determine if ‘count’ is outside the     range of 0 through 100:             if (count < 0 && count > 100)                                             T__   F__ 33. There is...

  • What is the value of GPA when grade is 'B' in the following code segment? int...

    What is the value of GPA when grade is 'B' in the following code segment? int GPA=0; switch (grade) { case 'A': case 'a': GPA = GPA + 1; case 'B': case 'b': GPA = GPA + 1; case 'C': case 'c': GPA = GPA + 1; case 'D': case 'd': GPA = GPA + 1; } 4 3 2 1 None of the above #2.   Branching - switch statements... Extra info/hint? It's free What is the value of GPA when...

  • the answer should be in C What is the output of the following: int whatIsThat(int *...

    the answer should be in C What is the output of the following: int whatIsThat(int * x); int main() int hold; int x[] = { 2,4,6,8); hold = whatIsThat(x); printf("%d, %d\n", x[0], hold); return 0; } int whatIsThat(int * a) { int i,sum=0; a[0] = a[O] + 6; for(i = 0; i <= 2; i++) (sum+= a[i]; a[i] = a[i] + 12; return sum; a. 20, 20 b. 20, 18 c. 18, 18 d. none of above What is the...

  • 5) What is the value of the variable answer after the code segment below completes? int...

    5) What is the value of the variable answer after the code segment below completes? int a, b, c; answer, a 3*b: b 5 10: c (a a b*b) / (c*c) answer = A).5 B) 2 C) 2.5 D) 250 ENone of the Above 8) What is the output of the following segment of code? int a 7, b= 3, c = 6 if (a> b c) printf"A"); if (b > a - с) printf ("B"); else printf("C") if (atb...

  • Given the following code segment, int x = 20; int y = 7; what is the...

    Given the following code segment, int x = 20; int y = 7; what is the data type of the value of the expression (x % y) ? (3 points) Question 1 options: 1) int 2) double 3) numeric 4) Error: possible loss of precision 5) Unable to be determined Question 2 (3 points) Given the following code segment, double x = 42.3; double y = 11.7; what is the data type of the value of the expression (x %...

  • Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int...

    Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...

  • QUESTION 6 What is the output of following C code? struct numbers     {         int x...

    QUESTION 6 What is the output of following C code? struct numbers     {         int x = 2;         int y = 3;     } int main() {   struct numbers nums;         nums.x = 110;         nums.y = 100;         printf("%d\n%d", nums.x, nums.y);         return 0; } A. Compile-time Error B. 110 100 C. 2 3 D. Run-time Error 2 points    QUESTION 7 What is the output of following C code? typedef struct student {         char *stud; }s1; int main() {   s1 s;         s.stud...

  • 18 C++ 1. What is the output of the following program segment? int y-22: while ((y...

    18 C++ 1. What is the output of the following program segment? int y-22: while ((y 3) != 0) cout << y<< "": y=y-2; The output is 2. Suppose that the input is 100, 20,-8, 50, 20. What is the output of the following C++ code? int sum0 int num: int j cin >> num: if (num < 0) continue зит зит + num; cout<< sum << endl; The output is

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT