Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2520 of 3366
380 Views
As per the question, the task is to find the nearest prime number by adding the prime number starting from 2 if the number N is not Prime.Input: N=6 Output: 11ExplanationSince 6 is not prime add first prime to 6 i.e. 2 which will result to 8 now 8 is also not prime now add next prime after 2 which is 3 which will give 8+3 = 11. Hence 11 is a prime number output will be 11.AlgorithmSTART Step 1- > declare num=15, i = num/2 Step 2 -> Loop For k=2 and k
2K+ Views
Given with a linked list program must print the list starting from the end till the front using the stack data structureInput : 10 -> 5 -> 3 -> 1 -> 7 -> 9 Output: 9 -> 7 -> 1 -> 3 -> 5 -> 10Here the user can use the approach of poping elements from the stack pointing top at the stack[0] location and than going till stack[n] elementAlgorithmSTART Step 1 -> create structure Linked_list Declare int data Declare struct linked_list *next End Step 2 -> declare int stack[30], top = -1 Step 3 -> declare struct ... Read More
1K+ Views
Given with inorder and preorder of a tree program must find the postroder traversal and print the sameInput: Inorder traversal in[] = {4, 2, 5, 1, 3, 6} Preorder traversal pre[] = {1, 2, 4, 5, 3, 6} Output: Postorder traversal post[] = {4, 5, 2, 6, 3, 1}AlgorithmSTART Step 1 -> declare function as find_value(int p, int in_order[], int n) Loop For i=0 and i declare function as postorder(int pre_order[], int in_order[], int n) Declare int variable as root = find_value(pre_order[0], in_order, n) IF root!=0 Call postorder(pre_order+1, in_order, root) End IF ... Read More
252 Views
The task is to print the given n number which have exactly two set bits that neither less than 2 nor more than 2.Set bits in computer language are the one that have value 1 and unset bits have value as 0Input: value of num=5 Output: 1 3 5 As 1 is equivalent to 1 in binary 3 is equivalent to 11 in binary 5 is equivalent to 101 in binaryAlgorithmSTART Step 1 -> declare variable as unsigned int num=5 and int i=1 Step 2 -> print i Step 3 -> Loop For i=3 and i
651 Views
Given with an array of elements and the task is to print those numbers whose digit sum is also prime and return -1 is not such digit exists in an arrayInput: arr[]={2, 4, 3, 19, 25, 6, 11, 12, 18, 7} Output : 2, 3, 25, 11, 12, 7Here, the given output is generated as it contains those additive numbers whose sum is also prime like − 2, 3, 7 are prime but 25(2+5=7), 11(1+1=2), 12(1+2=3) are also prime whereas numbers like 19(1+9=10) are not prime.AlgorithmSTART Step 1 -> Take array of int with values Step 2 -> declare start ... Read More
732 Views
Here, the task is to print those number in an array having 1, 2 and 3 as digits in their numbers and if their is no such number than the output must be -1Input : arr[] = {320, 123, 124, 125, 14532, 126, 340, 123400, 100032, 13, 32, 3123, 1100} Output : 123 3123 14532 100032 123400 Since the array have values with digits 1, 2 and 3 it wouldn’t return -1 and print 5 values that Contain 1, 2 and 3 in their respective numbers.AlgorithmSTART Step 1 -> Declare array with elements of int type as arr Step ... Read More
469 Views
Given a 2d array of n*n and the task is to find the antispiral arrangement of the given matrixInput : arr[4][4]={1,2,3,4, 5,6,7,8, 9,10,11,12 13,14,15,16} Output : 1 6 11 16 4 7 10 13AlgorithmSTART Step 1 -> declare start variables as r=4, c=4, i and j Step 2 -> initialize array as mat[r][c] with elements Step 3 -> Loop For i=0 and i print Step 5 -> Loop For i=0 and i
430 Views
Given a 2d array of n*n and the task is to find the antispiral arrangement of the given matrixInput : arr[4][4]={1,2,3,4, 5,6,7,8, 9,10,11,12 13,14,15,16} Output: 10 11 7 6 5 9 13 14 15 16 12 8 4 3 2 1For this, stack can be used where the transpose of a matrix can be pushed inside stack and poped reverselyAlgorithmSTART STEP 1 -> declare stack vector element as stk and variables as int r=4, c=4, i, j, rs=0 and cs=0 Step 2 -> store matrix elements in 2-3 array Step 3 -> Loop For i=0 and o
516 Views
Given with an array of int elements, the task is to arrange the elements in descending order and finding their occurrences.Input : arr[]={1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 6, 7, 7} Output : 7 occurs: 2 6 occurs: 1 5 occurs: 1 4 occurs: 1 3 occurs: 2 2 occurs: 3 1 occurs: 3AlgorithmSTART Step 1 -> input array with elements in sorting order Step 2 -> calculate size of an array by sizeof(a)/sizeof(a[0] Step 3 -> store size in a variable say en Step 4 -> Loop For i=siz-1 ... Read More
2K+ Views
In this article, we will learn how to print prime numbers from 1 to N in reverse order. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. Our goal is to find all prime numbers in the given range from 1 to N and then print them in reverse order. For example, given N = 20, the prime numbers between 1 and 20 are: 2, 3, 5, 7, 11, 13, 17, 19 The output should be the prime numbers printed in reverse order: 19, 17, 13, 11, 7, 5, ... Read More