Tutorial_6 - array of integers using the following header...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
TUTORIAL 6 Show the output for the following code a. #include <iostream> using namespace std; void swap(int n1, int n2) { int temp = n1; n1 = n2; n2 = temp; } int main() { int a[] = {1, 2}; swap(a[0], a[1]); cout << "a[0] = " << a[0] << " a[1] = " << a[1] << endl; return 0; } b. #include <iostream> using namespace std; void swap(int a[]) { int temp = a[0]; a[0] = a[1]; a[1] = temp; } int main() { int a[] = {1, 2}; swap(a); cout << "a[0] = " << a[0] << " a[1] = " << a[1] << endl; return 0; } c. Given the following program, show the values of the array in the following figure: #include <iostream> using namespace std; int main() { int values[5]; for (int i = 1; i < 5; i++) { values[i] = i; } 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
values[0] = values[1] + values[4]; return 0; } 1.Write a function that finds the smallest element in an
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: array of integers using the following header: double min( double array, int size) Write a test program that prompts the user to enter ten numbers, invokes this function, and displays the minimum value. Here is the sample run of the program: <Output> Enter ten numbers: 1.9 2.5 3.7 2 1.5 6 3 4 5 2 The minimum number is: 1.5 <End Output> Write a function that counts the number of letters in the string using the following header: int countLetters( const char s) Write a test program that reads a C-string and displays the number of letters in the string. Here is a sample run of the program: <Output> Enter a string: 2010 is coming The number of letters in 2010 is coming is 8 <End Output> 2...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

Tutorial_6 - array of integers using the following header...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online