[go: up one dir, main page]

0% found this document useful (0 votes)
53 views4 pages

Lab Sheet 05

1. The document contains instructions for 14 programming exercises involving arrays, functions, sorting, strings, and stacks. The exercises include creating a multiplication table with arrays, adding/subtracting/multiplying matrices, calculating stats of arrays, sorting arrays, checking balanced parentheses with stacks, and more.

Uploaded by

madmaxpie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views4 pages

Lab Sheet 05

1. The document contains instructions for 14 programming exercises involving arrays, functions, sorting, strings, and stacks. The exercises include creating a multiplication table with arrays, adding/subtracting/multiplying matrices, calculating stats of arrays, sorting arrays, checking balanced parentheses with stacks, and more.

Uploaded by

madmaxpie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

UNIVERSITY OF COLOMBO SCHOOL OF COMPUTING

COMPUTER SCIENCE DEGREE PROGRAMME


FIRST YEAR
SCS 1202 - Programming Using C
Lab Sheet 05

1. Create a multiplication table storing the values in a 2D array and then print the table.

2.

Using the above two matrixes write functions for matrixes addition, subtraction and multiplication.

1
3. Declare an array in the main method to store 15 double numbers given below.
34.5 56.7 12.6 98.4 54.21
89.55 54.2 98.4 73.2 21.45
34.5 98.4 21.45 98.4 9.3

Write separate methods in the C program to perform following operations.


a. Calculate the total of the elements in the array and then return the total.
b. Calculate the average of the elements in the array and then return the average.
c. Find the minimum element in the array and return.
d. Find the maximum elements in the array and return.
e. Find the element(s) which appears the maximum number of times in the array.

Call the above defined methods within the main method.

4. Write a program for given values of five students’ scores, gets the best score, and then assigns
grades based on the following scheme:
Grade is A If score is >= best - 10;
Grade is B If score is >= best - 20;
Grade is C If score is >= best - 30;
Grade is D If score is >= best - 40;
Grade is F otherwise.

5. Write a C program that reads in ten numbers and displays the number of distinct numbers and
the distinct numbers. (i.e., if a number appears multiple times, it is displayed only once).

6. The selection-sort method repeatedly finds the smallest number in the current array and swaps
it with the first number in the array. Rewrite this sorting by finding the largest number and
swapping it with the last number in the array. Write a C program for given ten integer numbers
to displays the sorted numbers.

2
7. Write a C program that shows the bubble sort algorithm for given 10 double numbers to
displays the sorted numbers. Use (6.0, 4.4, 1.9, 2.9, 3.4, 2.9, 3.5, 2.3, 7.5, 4.8) to test the
program.
(Hint: Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the
adjacent elements if they are in wrong order).

8. Given 5 non negative integers, write a C program to arrange them such that they form the
largest possible number.
Ex: 50, 2, 1, 9, 0 the largest formed number is 950210.

9. Write a method to count the number of 2s in given range of integers.


E.g.: 10,11,12 ,13,14,15,16,17,18,19,20

10. Write a C program to add 'ing' at the end of a given string (length should be at least 3). If the
given string already ends with 'ing' then add 'ly' instead. If the string length of the given string
is less than 3, leave it unchanged.

Sample String : eat


Expected Result : 'eating'
Sample String : 'string'
Expected Result : 'stringly'

11. Registration number of a student studying in faculty of Science has following properties.
• There should be only 8 characters.
• The first letter is ‘S’
• There should be exactly two ‘/’s.
• The batch of the student is expressed by the two digits given in between the two ‘/’s.
• Last three integers represent the student number.

3
Check whether a given registration number is valid? Provide the output as shown below.

Check your program for following registration numbers.


 S/09/867
 E/08/465
 S0967854
 S/096/76
 S//09475
 S//8/564
 S/0A/564
 S/A9/864
 S/09/67H
 S@09H4N

12. Write a C program to reverse a string using stack.


13. Write a C program to check balanced parentheses in expression using stack.
14. Write a C program to check whether the word “cord” is available in the following phrase.
“Cut your coat according to the cloth”

You might also like