Lab Sheet 05
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
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.
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.
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.