CS36 Lab 5
CS36 Lab 5
Q1 to Q5 - 1 point for each question, extra credit 1 point each for Q6 and Q7. Maximum of 7 points
total
The break, continue and goto C commands are not allowed to be used with loops. A
zero will be given for that question if your program contains a break, continue or goto
command used with loops. The break command is allowed only as part of the switch
statement.
Arrays
1. Write a program to interchange the largest and the smallest number in an array
a. Use functions – you must have a least these functions
i. main()
ii. void read_array(parameters,…) – to allow user to read the elements into the array
iii. void display_array(parameters,…) – to print the elements of the array
iv. you can create other functions as needed
b. NO GLOBAL Variables.
c. Sample test Run 1(red user input) Provide your data for test run 2 and 3.
Enter the desired size of the array: 5
Enter a number for position 0:3
Enter a number for position 1:6
Enter a number for position 2:3
Enter a number for position 3:7
Enter a number for position 4:9
2. Write a program to find the second largest integer number using an array of numbers
a. Use functions – you must have a least these functions
i. main()
ii. void read_array(parameters,…) – to allow user to read the elements into the array
iii. void display_array(parameters,…) – to print the elements of the array
iv. you can create other functions as needed
b. NO GLOBAL Variables.
c. Sample test Run 1(red user input) Provide your data for test run 2 and 3.
Enter the number of elements in the array: 6
c. Sample test Run 1(red user input) Provide your data for test run 2 and 3.
Enter the size of the array:6
1
2
3
3
4
5
______________________________________________________________________________________
Strings( no string methods or built-in string functions like strlen(), strcmp(), strcpy, etc… for questions
4,5,6,7)
4. Write a program to read and print the text until a * is encountered. Also, count the number of
characters in the text entered. Your program should read each character at a time. Do not forget to
terminate your string with ‘\0’ character.
Sample test Run 1(red user input) Provide your data for test run 2 and 3.
Enter * to end
Enter the text : Hi there*
The text is : Hi there
The count of the characters is : 8
5. Write a program to read a sentence which is a single string. Then count the number of words in the
sentence. The program will read in a string not one character at a time.
Sample test Run 1(red user input) Provide your data for test run 2 and 3.
6. Write a program to enter a text that has commas. Replace all the commas with semi colons and then
display the new text with semi colons. Your program will allow the user to enter a string not a
character at a time.
Sample test Run 1(red user input) Provide your data for test run 2 and 3.
7. Write a program to enter a text. Then enter a pattern and count the number of times the pattern is
repeated in the text. Your program will read in a string not a character at a time.
Sample test Run 1(red user input) Provide your data for test run 2 and 3.