Found 34484 Articles for Programming

C Program to print “Hello World!” without using a semicolon

Chandu yadav
Updated on 30-Jul-2019 22:30:25

5K+ Views

Let us see how to write a C program in which we can print the text “Hello World” without using any semicolon.We can simply write the text by using the line printf(“Hello World”); in the main() function.But there is a semicolon at the end of the line. To avoid the semicolon, we can follow some trick. We can use the same printf() statement inside if condition. As the printf() statement returns the length of the text, so it is non zero value, so the if statement will be true. Thus the text will be written on screen.Example Code#include main() { ... Read More

C++ Program to Generate Random Numbers Using Probability Distribution Function

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

1K+ Views

Probability Density Function (pdf), is a function that describes the relative likelihood for this random variable to take on a given value. It is also called as density of a continuous random variable.The probability of the random variable fall within a particular range of values is given by the integral of this variable’s density over that range, So, it is given by the area under the density function but above the horizontal axis and between the lowest and greatest values of the range. Probability Distribution is based upon this probability density function.AlgorithmBegin Declare n ... Read More

C++ Program to Generate Random Numbers Using Middle Square Method

Nancy Den
Updated on 30-Jul-2019 22:30:25

915 Views

The middle-square method is one of the simplest method of generating random numbers. this method will either begin repeatedly generating the same number or cycle to a previous number in the sequence and loop indefinitely. For a generator of ndigit random numbers, the period can be no longer than n. If the middle n digits are all zeroes, the Generator then outputs zeroes forever, while these runs of zero are easy to detect, they occur too frequently for this method to be of practical use.Input − Enter the digit for random number:4 Output − The random numbers are: 6383, 14846, ... Read More

Program to print numbers from 1 to 100 without using loop

George John
Updated on 30-Jul-2019 22:30:25

554 Views

Here we will see how to write a C program that can print numbers from 1 to 100 without using any kind of loops.This problem can be solved using the recursion. We will create a function that will be called recursively. As we know that a recursive function has basically two sections. The base case and the recursive call and other operation. In this function the base case is the argument n is greater than 1. Until it reaches 1, the function will be called recursively. Now at the end it will print the value of n. Thus the entire ... Read More

C Program to print “Even” or “Odd” without using Conditional statement

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

9K+ Views

In this section we will see how to check whether a number is odd or even without using any kind of conditional statements like (=, ==).We can easily check the odd or even by using the conditional statements. We can divide the number by 2, then check whether the remainder is 0 or not. if 0, then it is even. Otherwise we can perform AND operation with the number and 1. If the answer is 0, then it is even, otherwise odd.Here no conditional statements can be used. We will see two different methods to check the odd or even.Method ... Read More

C Program to sum the digits of a given number in single statement

Chandu yadav
Updated on 30-Jul-2019 22:30:25

397 Views

In this section we will see how to find the sum of digits without writing multiple statements. In other words, we will find the sum of digits in a single statement.As we know that, to find the sum of digits we cut the last digit by taking the remainder after dividing the number by 10, and then divide the number by 10 again and again until the number becomes 0.To do these task in a single statement the for loop can be used. As we know there are three different sections in the for loop. In the initialization phase we ... Read More

C++ Program to Implement the linear congruential generator for Pseudo Random Number Generation

Nancy Den
Updated on 30-Jul-2019 22:30:25

897 Views

The linear congruential generator is a very simple example of a random number generator. It is one of the oldest and best-known pseudorandom number generator algorithms. The function which is used in this method −Xn+1=(aXn + C) mod mwhere X is the sequence of pseudorandom values, andm,0

C Program to print numbers from 1 to N without using semicolon

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

970 Views

Here we will see a tricky solution of the problem. We shall print some numbers from 1 to N without using any semicolon.We can solve this problem in two different methods. The first one is the Iterative method, and second one is recursive method.Method 1The printf() function returns the length of the string so it is a non-zero value. We can perform logical AND with the condition to print the result. Then increase the value of the counter.Example Code#include #define N 20 int main(int num, char *argv[]) { while (num

C++ Program to Check Whether a Directed Graph Contains a Eulerian Cycle

Nancy Den
Updated on 30-Jul-2019 22:30:25

465 Views

The Euler cycle/circuit is a path; by which we can visit every edge exactly once. We can use the same vertices for multiple times. The Euler Circuit is a special type of Euler path. When the starting vertex of the Euler path is also connected with the ending vertex of that path, then it is called the Euler Circuit.To check whether a graph is Eulerian or not, we have to check two conditions −The graph must be connected.The in-degree and out-degree of each vertex must be same.Input − Adjacency matrix of the graph.0100000100000111000000100Output − Euler Circuit FoundAlgorithmtraverse(u, visited)Input − The ... Read More

C++ Program to Check Whether a Graph is Strongly Connected or Not

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

302 Views

In directed graph components are said to be strongly connected, when there is a path between each pair of vertices in one component.To solve this algorithm, firstly, DFS algorithm is used to get the finish time of each vertex, now find the finish time of the transposed graph, then the vertices are sorted in descending order by topological sort.Input: Adjacency matrix of the graph.0011010000010000000100000Output: Following are strongly connected components in given graph −0 1 2 3 4Algorithmtraverse(graph, start, visited)Input: The graph which will be traversed, the starting vertex, and flags of visitednodes.Output: Go through each node in DFS technique and ... Read More

Advertisements