## QBasic Program to Reverse a Number

Write a program in QBasic to reverse a number. For example, Input 12345 Output 54321 Steps to Reverse A Number Let n be the input number. Declare a variable temp and set temp = n. Declare a variable num. Set num = 0. Repeat the following steps while temp > 0 Set r = temp …

## C Program to Print the Rightmost Digit of a Given Number

Write a program to print the rightmost ( last ) digit of a given number in C. For example, Input 821309 Output 9 The problem is very simple. The right-most digit of a number is basically the remainder of that number with 10. We can use the ‘%’ operator to get the remainder. Output Now, …

## C Program to Calculate Sum of Non-diagonal Elements in a Matrix

Write a program to calculate sum of non-diagonal elements in a matrix in C/C++. For example, Input 1 2 2 0 3 0 1 1 1 Output Sum of non-diagonal elements: 6 Before we go any further, we need to understand what a non-diagonal element is. An element of a square matrix is a non-diagonal …

## Java Program to Count the Frequency of Each Vowel in a Given String

Write a program to count the frequency of each vowel in a given string in Java. For example, Input “My name is John Smith” Output Number of ‘a’ = 1  Number of ‘e’ = 1   Number of ‘i’ = 2  Number of ‘o’ = 1  Number of ‘u’ = 0 Steps Let str be the input string. Initialize an integer array of size 5. Let the name of the array be cnt. Fill cnt with …

## QBasic Program to Sort Numbers in Ascending Order

Write a program to sort numbers in ascending order in QBasic. For example, Input 1 5 4 3 7 8 9 Output 1 3 4 5 7 8 9 Steps First, the user enters the size of array/list. Let it be n. After that, the user is asked to enter n numbers. Then we sort …

## C Program to Print Last Two Digits of a Number

Write a C program to print last two digits of a number. For example, Input 123456 Output 56 We can easily find the last two digit of a number using modules 100. Let N be the input. If N is a one-digit number, simply print N and terminate the program. Let temp = N % …

## C Program to Find Second Last Digit of a Number

Write a C program to find the second last digit of a number. For example, Input 123456 Output 5 Steps Let N be the input number. If N is a one-digit number, return -1. Set N = N / 10. This step removes the last digit of N. N % 10 gives us the last …

## C Program to Return Second Word of a String in Uppercase

Write a program to return second word of a string in uppercase in C language. For example, Input My name is John Smith Output NAME Steps Let the input string be str. Set i = 0. Increment i until str[i] is equal to blank character. By doing so, we are basically skipping the first word …

## Bozo-Sort

Bozo-Sort is a variation of Bogosort. It is another highly inefficient randomized algorithm based on the trial and error approach. Bozo-sort sorts the input list by repeatedly swapping 2 random elements of the list and checking if the list is sorted or not. The process is repeated till the input list is sorted. Implementation In …

## Bogosort

Bogosort is just another sorting algorithm. Bogosort is highly inefficient compared to other sorting algorithms. It is a randomized algorithm and is based on the trial and error paradigm. Bogosort basically generates random permutations of the input list and check if the list is sorted or not. This process is continued until the input list …