Programming Articles - Page 2490 of 3366

C vs BASH Fork bomb?

sudhir sharma
Updated on 08-Aug-2019 08:09:29

312 Views

Fork() bomb is a Dos (Denial Of Service) attack against the linux based system. This calls the Fork() system infinite number of times that fills the memory of the program and intends to harm the system.Bash script for fork bomb:(){ :|: & };:The code explained as :( ) is function definition, { } defines the body of the loop. :|:& create a memory location and does not allow it to get deallocated. This program call itself multiple number of time again and again. Thus calling infinite calls.C Fork bomb is also the same type of Dos but it can be ... Read More

C/C++ Programming to Count trailing zeroes in factorial of a number?

sudhir sharma
Updated on 08-Aug-2019 08:06:48

878 Views

Counting the number of trailing zeroes in a factorial number is done by counting the number of 2s and 5s in the factors of the number. Because 2*5 gives 10 which is a trailing 0 in the factorial of a number.ExampleFactorial of 7 = 5040, the number of trailing 0’s is 1.Based on our logic 7! = 2*3*4*5*6*7, it has 3 2s and 1 5s so the number of trailing 0’s is 1.#include using namespace std; int main() {    int n = 45;    int count = 0;    for (int i = 5; n / i >= 1; i *= 5)       count += n / i;    cout

Sum of squares of first n natural numbers in C Program?

sudhir sharma
Updated on 08-Aug-2019 08:01:53

14K+ Views

The sum of squares of the first n natural numbers is found by adding up all the squares.Input - 5Output - 55Explanation - 12 + 22 + 32 + 42 + 52There are two methods to find the Sum of squares of first n natural numbers −Using Loops − the code loops through the digits until n and find their square, then add this to a sum variable that outputs the sum.Example#include using namespace std; int main() {    int n = 5;    int sum = 0;    for (int i = 1; i >= n; i++)       sum += (i * i);    cout

C++ Programming for Smallest K digit number divisible by X?

sudhir sharma
Updated on 08-Aug-2019 07:55:02

138 Views

Smallest K digit number that divisible by X is found using the formula by checking divisible by X. The formula works in the following way −Compute minimum K digit number [min] for example: 10/100/1000 etc.Now find if min is divisible by X. if yes, then this is the answer.If not, then min+X - ([min+X]%k) is the answer.Example#include #include using namespace std; int main() {    int X = 83;    int K = 5;    cout

Write you own Power without using multiplication(*) and division(/) operators in C Program

sudhir sharma
Updated on 08-Aug-2019 07:44:49

492 Views

Power function is calculated using the times multiple i.e. 5n is 5*5*5… n times. For this function, to work properly without using multiplication(*) and division(/) operators we will use nested loops that add the numbers n number of time.Example#include using namespace std; int main() {    int a= 4 , b = 2;    if (b == 0)       cout

Sum of squares of the first n even numbers in C Program

sudhir sharma
Updated on 08-Aug-2019 07:41:42

2K+ Views

The sum of squares of the first n even numbers means that, we first find the square and add all them to give the sum.There are two methods to find the sum of squares of the first n even numberUsing LoopsWe can use loops to iterate from 1 to n increase number by 1 each time find the square and add it to the sum variable −Example#include using namespace std; int main() {    int sum = 0, n =12;    for (int i = 1; i

To count Vowels in a string using Pointer in C++ Program

sudhir sharma
Updated on 08-Aug-2019 07:36:50

2K+ Views

Finding the number of vowels in a string using pointers need you to understand string, vowels and how to use pointer with string.String is an array of characters. And vowels are characters from the set {a, e, i, o, u}. Pointer is a variable that stores the value of memory location on a variable.To find the number of vowels in a string. We will traverse the string and then compare each character with vowels and if it is equal then it increase a counter otherwise not.Condition of the below code is that it requires a string that has all lowercase ... Read More

To find sum of even factors of a number in C++ Program?

sudhir sharma
Updated on 30-Oct-2019 06:20:56

317 Views

This program is used to find all the even factors and calculate the sum of these even factors and display it as output.Example −Input : 30 Even dividers : 2+6+10+30 = 48 Output : 48For this, we will find all the factors. Find the even of them and find the sum, Else, we will use the formula to find the sum of factors using the prime factors, Sum of divisors = (1 + d11 + d12 ... d1a1) *(1 + d21 + d22 ... d2a2) *...........................* (1 + dk1 + dk2 ... dkak) Here di = prime factors ; ai ... Read More

5 Different methods to find the length of a string in C++?

sudhir sharma
Updated on 08-Aug-2019 07:07:55

2K+ Views

A sequence of characters or a linear array of character is known as String. Its declaration is same as define other arrays.Length of array is the number of characters in the String. There are many in-built method and other methods to find the length of string. Here, we are discussing 5 different methods to find the length of a string in C++.1) Using the strlen() method of C − This function returns an integer value of the C. For this you need to pass the string in the form of character array.PROGRAM TO ILLUSTRATE THE USE OF strlen() METHOD#include ... Read More

10 Interesting Python Cool Tricks

Shriansh Kumar
Updated on 12-Jul-2025 23:54:14

6K+ Views

With the increase in popularity of the Python programming language, more and more features are becoming available for Python developers. Usage of these features helps us to write efficient code. In this article, we will see 10 Python tricks that are very frequently used. Reversing a List We can reverse a given list by using the reverse() function. It returns the elements of the current list in reverse order. It works with both numeric and string datatypes. Example Let's see how to use the reverse() function in your Python program to reverse a list of strings: List = ["Shriya", "Lavina", "Sampreeti" ... Read More

Advertisements