Posts

Showing posts with the label C Programming

Map string to alphanumeric keypad in C

Image
If you haven't understood the title, here is an explanation:     Input a string     The program will tell you what buttons you need to press how many times in an alpha numeric keypad. Example:     input: blog     output: 22 55 666 4 Logic?     - Initialise a 2D array which holds values of all buttons.     - Get the input string.     - Loop through each elements in the array and check it with the 2D array.     - The row index will tell you which button should be pressed.     - The column index will tell how many times to press it.     - In each loop concat the row index with the result string and display it !! 2D array for keypad: The 2D initialisation:       10 rows and max number of characters in a button : 4     char keys[10][4]={ "XXXX",                        "...

Second smallest element in array (C Programming)

The following program I scribbled, for finding the second smallest number in an integer array in C   program. The logic? Simple and childish !!! Get the length Get the array contents Find the smallest number in the array with a for loop Again loop through the elements to find number which is smaller than the rest of the elements but greater than the smallest element you just found. There !! you found the second smallest number !!! The c program: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 #include<stdio.h> int main () { int xArray [ 10 ]; int Length ; int smallInt ; int i , j , l ; int xSecodSmall ; printf ( "Enter the number of elements min(1) max(2):\t" ); Length = 11 ; scanf ( "%d" , & Length ); while ( Length > 10 | Length < 2 ) { printf ( "\...