Server Side Programming Articles - Page 2198 of 2646

3-digit Osiris number C Program?

Arnab Chakraborty
Updated on 19-Aug-2019 14:07:54

197 Views

Here we will see the Osiris number. An Osiris number is such kind of number that are equal to the sum of permutations of sub-samples of their own digits. Suppose the number is 132. Then if we calculate {12 + 21 + 13 + 31 + 23 + 32} this is also 132. So the number is Osiris number. We have to check whether the given number is Osiris number or not.Approach is simple. If we analyze the numbers, each digit is occurring twice so they are in ones position and tens position. So we can check by multiplying 11 ... Read More

Add the elements of given arrays with given constraints?

sudhir sharma
Updated on 19-Aug-2019 12:24:27

288 Views

For this problem, to add elements of two given arrays we have some constraints based on which the added value will get changed. the sum of two given arrays a[] & b[] is stored into to third array c[]in such a way that they gave the some of the elements in single digit. and if the number of digits of the sum is greater than 1, then the element of the third array will split into two single-digit elements. For example, if the sum occurs to be 27, the third array with store it as 2, 7.Input: a[] = {1, ... Read More

Add all greater values to every node in a given BST?

sudhir sharma
Updated on 01-Jul-2020 14:57:28

277 Views

A BST or binary search tree is a form of binary tree that has all left nodes smaller and all right nodes greater than the root value. For this problem, we will take a binary tree and add all the values greater than the current node to it. the problem “ add all greater values to every node in BST” is simplified as for a BST add all the node values that are greater than the current node value to that node value.Add all greater values to each node in the BST Problem Statement:Given a Binary Search Tree (BST), we ... Read More

Add 1 to a number represented as a linked list?

sudhir sharma
Updated on 19-Aug-2019 12:34:52

658 Views

The linked list representation of a number is provided in such a way that the all nodes of the linked list are treated as one digit of the number. The node stores the number such that the first element of the linked list holds the most significant digit of the number, and the last element of the linked list holds the least significant bit of the number. For example, the number 202345 is represented in the linked list as (2->0->2->3->4->5).And to add one to this linked list represented number we have to check the value of the least significant bit ... Read More

A Number Link Game?

sudhir sharma
Updated on 02-Jul-2020 05:37:51

809 Views

Number link is a type of logic puzzle involving finding paths to connect numbers in a grid.A simple example of a Numberlink puzzle The solution to the Numberlink puzzleRules − The player has to pair up all the matching numbers on the grid with single continuous lines (or paths). The lines cannot branch off or cross over each other, and the numbers have to fall at the end of each line (i.e., not in the middle). It is considered that a problem is well-designed only if it has a unique solution and all the cells in the grid are filled, ... Read More

C program to calculate the value of nPr?

sudhir sharma
Updated on 19-Aug-2019 11:55:15

354 Views

Permutations, nPr can also be represented as P(n,r) is a mathematical formula to find the number of permutations. The formula of P(n, r) is n! / (n – r)!.The number of permutations on a set of n elements is given by n! where “!” represents factorial.Input:n=5;r=4; Output:120ExplanationP(5, 4) = 5! / (5-4)! => 120 / 1 = 120 5!=1*2*3*4*5*=120Example#include using namespace std; long int fact(int x) {    int i, f=1;    for(i=2; i

C Program for Decimal to Binary Conversion?

sudhir sharma
Updated on 19-Aug-2019 11:53:39

1K+ Views

Convert an integer from decimal number system (base-10) to binary number system (base-2). Size of an integer is assumed to be 32 bits, need you to divide the number by the base. It is used by the computer to change integer values to bytes that are a computer.Input:10 Output:1010ExplanationIf the Decimal number is 10When 10 is divided by 2 remainders is zero. Therefore, 0.Divide 10 by 2. New number is 10/2 = 5.when 5 is divided by 2 Remainder is 1. Therefore 1.Divide 5 by 2. New number is 5/2 = 2.when 2 is divided by 2 Remainder is ... Read More

C program to Find the Largest Number Among Three Numbers

sudhir sharma
Updated on 19-Aug-2019 11:50:53

832 Views

This program takes the 3 numbers and finds the biggest among all. For this, we will compare the numbers with each other and find out which is the largestInput: a=2,b=4,c=7 Output:7 Largest NumberExplanationThis program uses only if statement to find the largest number.Example#include using namespace std; int main() {    int a,b,c;    a=2,b=4,c=7;    if(a>b) {       if(a>c) {          printf("%d Largest Number ",a);       } else {          printf("%d Largest Number ",c);       }    } else {       if(b>c) {          printf("%d Largest Number ",b);       } else {          printf("%d Largest Number ",c);       }    }    return 0; }

C program to Check Whether a Number is Positive or Negative or Zero?

sudhir sharma
Updated on 19-Aug-2019 11:49:19

1K+ Views

A number which is greater than 0 is positive and less than 0 are negative. The concept of positive and negative is very important in number theory and programming also. Calculations rely on this concept only.Input: 0 Output:0 is zeroExplanationUsing conditional statement check the number with 0 weather it is greater than 0 or smaller than 0.Example#include using namespace std; int main() {    int n=0;    if(n>0) {       printf("%d is positive",n);    } else if(n

C Program to Check Armstrong Number?

sudhir sharma
Updated on 19-Aug-2019 11:47:26

440 Views

A number is called an Armstrong number if the sum of cubes of digits of the number is equal to the number itself. It is a mathematical concept usually used in programming to build basic logic of the programmerInput:370 Output:370 is an Armstrong NumberExplanation370 = 3*3*3 + 7*7*7 + 0*0*0 = 27 + 343 + 0 = 370Exampleinclude using namespace std; int main() {    int n, num, rem, sum = 0;    cin >> n;    num = n;    while(num != 0) {       digit = num % 10;       sum += digit * digit * digit;       num /= 10;    }    if(sum == n)       printf("%d is an Armstrong number.", n );    else       printf("%d is not an Armstrong number.",n);    return 0; }

Advertisements