Arrays-Computer Programming-Quiz, Exercises of Computer Engineering and Programming

This quiz was taken by Prof. Mala Narasinha in class Computer Programming course at B R Ambedkar National Institute of Technology. It includes: Console, Index, Function, Array, Sample, Input, Output, Alphabetical, Order, Size, Sort

Typology: Exercises

2011/2012

Uploaded on 07/13/2012

aken
aken 🇮🇳

5

(1)

26 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name:___________________ Reg No:_________________________
COMPUTER PROGRAMMING (CS 1124) SPRING 2012
CLASS TEST
TOTAL POINTS: 100 TOTAL TIME: 75 MINS
1. [20 points] A: Show the output of following code as it will appear to console while
executing?
int myArray[4][4], index1, index2;
for (index1 = 0; index1 < 4; index1++)
for (index2 = 0; index2 < 4; index2++)
myArray[index1][index2] = index2;
for (index1 = 0; index1 < 4; index1++)
{
for (index2 = 0; index2 < 4; index2++)
cout << myArray[index1][index2] << " ";
cout << endl;
}
B: Consider the following function definition:
void too2(int a[], int howMany)
{ for (int index = 0; index < howMany; index++)
a[index] = 2;
}
Which of the following are acceptable function calls?
int myArray[29];
too2(myArray, 29);
too2(myArray, 10);
too2(myArray, 55);
“Hey too2. Please come over here.”
int yourArray[100];
too2(yourArray, 100);
too2(myArray[3], 29);
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Arrays-Computer Programming-Quiz and more Exercises Computer Engineering and Programming in PDF only on Docsity!

COMPUTER PROGRAMMING (CS 1124) SPRING 2012

CLASS TEST

TOTAL POINTS: 100 TOTAL TIME: 75 MINS

  1. [2 0 points] A: Show the output of following code as it will appear to console while executing?

int myArray[4][4], index1, index2;

for (index1 = 0; index1 < 4; index1++) for (index2 = 0; index2 < 4; index2++) myArray[index1][index2] = index2; for (index1 = 0; index1 < 4; index1++) { for (index2 = 0; index2 < 4; index2++) cout << myArray[index1][index2] << " "; cout << endl; }

B: Consider the following function definition:

void too2(int a[], int howMany) { for (int index = 0; index < howMany; index++) a[index] = 2; } Which of the following are acceptable function calls?

int myArray[29];

too2(myArray, 29); too2(myArray, 10); too2(myArray, 55); “Hey too2. Please come over here.”

int yourArray[100];

too2(yourArray, 100); too2(myArray[3], 29);

  1. [20 points] Declare two arrays of sizes 10 each in main(). Pass these arrays to a function common_elements(). Function common_elements() will display the elements which are common in both arrays. Sample Input: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 and 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 Sample Output: Common elements are 2, 4, 6, 8, 10
  1. [20 points] Write a program which will take a 2 - Dimentional array of three rows and three columns from the user and then print the array in reverse order.

Sample Input Sample Output 1 2 3 9 8 7 4 5 6 6 5 4 7 8 9 3 2 1

  1. [20 points] Write a program to display the average of the left diagonal of a square matrix of size 5x5.