Question: Write a program that changes the case of each character in a string. If its uppercase, convert it to lowercase and vice-versa. Input: ThE quiCK brOwN FOX jUMPs. Output: tHe QUIck BRoWn fox Jumps. In this program we shall apply the basic principle that each character is represented as an integer ASCII code. For more reference look into the post – Find the case of a character input by the user. Now we know that ‘a’ -> ASCII CODE = 97 ‘A’ -> ASCII CODE = 65 Thus the …
-
-
Strings
Write a program to find the case of a character entered from the keyboard.
by nikoo281 minutes readQuestion: Write a program that returns the case of the character? Input: e Output: lower case We shall use the concept of ASCII characters to determine the case of the character input by the user. The ASCII table can be found at this link. ASCII TABLE From this we can see the following ASCII codes:- CHARACTER ASCII CODE A 65 Z 90 a 97 z 122 Thus, to check the case we simply compare the ASCII codes. Since we are using C language, in C every character is considered as …
-
Merge Sort is one of the most popular methods of sorting an array and as offers a constant operating time of . And, as the name suggests it involves merging of several sorted arrays to combine and form a single sorted arrays in the end. The steps involved in merge sort are:- Divide the array in 2 parts left and right. Now recursively divide the left and right parts into more left and right sub parts. Keep doing step 2 , until the sub parts are no greater than a …
-
Question: We have 2 sorted arrays and we want to combine them into a single sorted array. Input: arr1[] = 1, 4, 6, 8, 13, 25 || arr2[] = 2, 7, 10, 11, 19, 50 Output: 1, 2, 4, 6, 7, 8, 10, 11, 13, 19, 50 One of the simplest ways to solve this problem would be to copy both the arrays into a new array and then apply some sorting technique on them. But this method will not utilize the fact that both the arrays are already sorted. …
-
Bubble sort is one of the simplest sorting algorithms and it works on the principle of swapping two elements. Think of the bubble sort as a water bubble that arises from the bottom of the ocean. As it rises up, it grows in size and its the maximum when it reaches the surface. Similarly, in bubble sort, we arrange items from smallest to the largest at the end one by one in each iteration.The algorithm for bubble sort is as follows:- We start from the bottom of the array and …
-
As the name suggests SELECTION SORT involves selecting an element. Now the question arises, as to how should we select this element. What is the criteria? Where should we put it? All these answers are given in the algorithm for SELECTION SORT. In selection sort, what we do is:- Start from the first position in the array. Traverse the remaining array to find the smallest number Swap this smallest number with the number we selected in the first place. Repeat steps 2 and 3 with the next position. Let us …
-
Insertion sort is the most generic example of a sorting algorithm, and the one which is used by one of the most naive users. Often we must have also used this algorithm in our real life examples unknowingly. One of the favorite example is:- This is a very common scenario and we must have used it. Suppose you get a hand of cards. Our general approach is that we start scanning the cards from starting and if we find a card out of place, we remove it from there and …
