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
Server Side Programming Articles - Page 2212 of 2650
174K+ Views
There is a need to generate random numbers when studying a model or behavior of a program for different range of values. Python can generate such random numbers by using the random module. In the below examples we will first see how to generate a single random number and then extend it to generate a list of random numbers.Generating a Single Random NumberThe random() method in random module generates a float number between 0 and 1.Exampleimport random n = random.random() print(n)OutputRunning the above code gives us the following result −0.2112200Generating Number in a RangeThe randint() method generates a integer between ... Read More
2K+ Views
Greatest common divisor or gcd is a mathematical expression to find the highest number which can divide both the numbers whose gcd has to be found with the resulting remainder as zero. It has many mathematical applications. Python has a inbuilt gcd function in the math module which can be used for this purpose.gcd()It accepts two integers as parameter and returns the integer which is the gcd value.SyntaxSyntax: gcd(x, y) Where x and y are positive integers.Example of gcd()In the below example we print the result of gcd of a pair of integers.import math print ("GCD of 75 and 30 ... Read More
382 Views
This function helps in converting a mutable list to an immutable one. This is needed when we have declared a list whose items are changeable but after certain steps we want to stop allowing the elements in it to change. In such scenario, we apply the frozenset() function as shown below.SyntaxSyntax: frozenset(iterable_object_name)In the below example we take a list, change its element and print it. Then in the next step we apply the frozenset function, and try changing the element again. In the second step we get the error showing that the list can not be modified anymore.Example# Before applying ... Read More
1K+ Views
C programming puzzles are small but tricky coding problems, which are designed to challenge and to understand the C programming language in a better way. Problem Statement We are given two numbers, and our task is to combine them in such a way that the second integer is placed before the first integer, resulting in a single combined integer. But here, we are not allowed to use any logical, arithmetic, string-related operations, or any pre-defined functions. Consider the following input/output scenarios to understand the puzzle statement better: Scenario 1 Input: 12, 54 Output: 5412 Explanation: Here, the second ... Read More
2K+ Views
These two methods are part of python math module which helps in getting the nearest integer values of a fractional number.floor()It accepts a number with decimal as parameter and returns the integer which is smaller than the number itself.SyntaxSyntax: floor(x) Where x is a numeric valueExample of floor()In the below example we take different types of numeric values like, integer, positive decimal and negative decimal and apply the floor function to them. We get the nearest integer which is less than the numeric value supplied.import math x, y, z = 21 , -23.6 , 14.2 print("The value of ", x, ... Read More
262 Views
This an array based puzzle that need you to change all the numbers of an array the contains two elements to 0. One element of the array is 0 and other may or may not be 0.To solve this puzzle the program needs to find the non-zero element and change in to 0.Their are the following constraints that are needed to solve the boolean array puzzle −Allowed operation is complement, other operations are not allowed.Loops and conditional statements are not allowed.Direct assignment is also not allowed.PROGRAM TO SOLVE BOOLEAN ARRAY PUZZLE#include using namespace std; void makeZero(int a[2]) { a[ ... Read More
3K+ Views
An abundant Number (also known as excessive number) is a number in the number theory which itself is smaller than the sum of all its proper divisors. For example, 12 is an abundant Number : divisors 1, 2, 3, 4, 6 , sum =16 >12.The difference between the sum of divisors and the number is called abundance. For above example abundance = 4 => 16 - 12 .To check for abundant number we will find all the factors of the number and add them up. This sum compared with the number show that if the number is abundant or not.PROGRAM ... Read More
478 Views
The abs function in C++ is used to find the absolute value of a complex number. The absolute value of a complex number (also known as modulus) is the distance of that number from the origin in the complex plane. This can be found using the formula −For complex number a+bi:mod|a+bi| = √(a2+b2)The abs() function returns the result of the above calculation in C++. It is defined in the complex library that is needed to be included.PROGRAM TO SHOW USE OF abs() FUNCTION FOR COMPLEX NUMBERS IN C++#include #include using namespace std; int main () { float ... Read More
179 Views
An array stores number of same data type. For an array there may arise a situation when you need to store 2-3 values that are same i.e. 3,3,3,3 needs to be stored.For this case, the programing language C has made a simple way to create an array with such repeated value to reduce the workload of the programmer.Syntax[startofRepeatingSeq … EndofRepeatingSeq]number Example : For 3 repeated 5 times ; [0 … 4]3Example#include int main() { int array[10] = {[0 ... 4]3, [6 ... 9]5}; for (int i = 0; i < 10; i++) printf("%d ", array[i]); return 0; }Output3 3 3 3 3 0 5 5 5 5
693 Views
Modified game of Nim is an optimisation games of arrays. This game predicts the winner based on the starting player and optimal moves.Game Logic − In this game, we are given an array{}, that contains elements. There are generally two players that play the game namly player1 and player2. The aim of both is to make sure that all their numbers are removed from the array. Now, player1 has to remove all the numbers that are divisible by 3 and the player2 has to remove all the numbers that are divisible by 5. The aim is to make sure that ... Read More