Found 1339 Articles for C

Print 1 2 3 infinitely using threads in C

sudhir sharma
Updated on 03-Feb-2020 10:15:24

486 Views

Here, we have to print 1 2 3 sequences repeatedly infinite number of times using threads in the c programming language.Let’s see the sample output that we want from our code, 1 2 3 1 2 3 1 2 3 1 2 3For this, we will have to use three threads that are running side by side in the C programming language. And a variable that is initialized to one in the first thread whose value will be updated based on its last value. And run an infinite loop in the function.ExampleLet’s see the program to implement our solution, #include ... Read More

Print 2D matrix in different lines and without curly braces in C/C++

sudhir sharma
Updated on 03-Feb-2020 09:58:11

272 Views

Here, we will see the code that will print a 2D matrix in c/c++ programming language without using curly braces.Curly braces are separators in a programming language that are used to define separate code blocks in the program. Without curly braces defining scopes is difficult in c/c++.Let’s see the basic code and sample output to print 2D matrix.Example Live Demo#include using namespace std; int main() {    int arr[2][2] = {{12, 67},    {99, 5}};    int n = 2, m = 2;    for (int i = 0; i < m; i++){       for (int j = 0; j < n; j++){          cout

Integer to Roman in C

Arnab Chakraborty
Updated on 27-Apr-2020 11:57:00

7K+ Views

Given a decimal number n, we have to convert this into Roman numeral. The value n lies in the range 1 to 4000. These are some Roman Numerals.NumberNumeral1I4IV5V9IX10X40XL50L90XC100C400CD500D900CM1000M4000MMMMSo if the number n = 859, its Roman Numeral will be DCCCLIXTo solve this, we will follow these stepsDefine an array to store numeral and corresponding values for the given list. That is called nume arraywe are using a recursive approach, the function decToRom() is used. this is taking nume array and the number num.The decToRom() will be likeif num is not 0, thenmax := find maximum value from nume array that ... Read More

C program for file Transfer using UDP?

Arnab Chakraborty
Updated on 29-Jan-2020 12:18:08

1K+ Views

Data can be shifted between two computers implementing Socket programming in C.In same case, files can easily be sent implementing User Datagram Protocol(UDP) and a simple client/server.Security − Handled by encryption.Protocol − UDPEncryption − XOR encryptionAlgorithmThe server is started and waited for filename.A filename is sent by the client.This filename is received by the server. If file is present, server starts reading file and is continued to send a buffer filled with file contents encrypted until and unless file-end is reached.End of File is marked by EOF.File is received as buffers until and unless EOF is received. After that it ... Read More

Binary Number System - Overflow in Arithmetic Addition in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 11:43:59

873 Views

2’s Complement Number System is widely implemented in computer architecture.N-bit 2’s Complement number System can be able to represent Number from -2n-1 to 2n-1- 14 Bit can be able to represent numbers from ( -8 to 7 )5 Bit can be able to represent numbers from ( -16 to 15 ) in 2’s Complementary System.Overflow happens with respect to addition when 2 N-bit 2’s Complement Numbers are appended and the answer is too large to fit into that N-bit Group.A computer contains N-Bit Fixed registers. Result of addition of two N-Bit Number will result maximum N+1 Bit number.Carry Flag stores ... Read More

Barabasi Albert Graph (for Scale Free Models) in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 11:00:00

296 Views

The Barabási-Albert model is treated as one of several proposed models that produce scale-free networks. It combines two important general concepts: growth and preferential attachment. Both concepts i.e. growth and preferential attachment have wide existence in real networks. The meaning of growth is that the number of nodes in the network increases over time.The meaning of preferential attachment is that the more connected a node is, the more chance it is to receive new links.Higher degree nodes have stronger ability to catch or grab links added to the network. Basically, the preferential attachment can be well understood if we think ... Read More

Arrange a binary string to get maximum value within a range of indices C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 08:14:40

255 Views

In case of a given string consisting of only 0’s and 1’s, we are given M non-intersecting ranges A, B( A

An application on Bertrandís ballot theorem in C/C++

Arnab Chakraborty
Updated on 29-Jan-2020 07:51:43

212 Views

In Bertrand's original paper, he explains a proof depended on a general formula for the number of favourable sequences implementing a recursion relation.ExampleLet there are 5 voters, of whom 3 vote for candidate A and 2 vote for candidate B (so p = 3 and q = 2). Ten possibilities are exist for the order of the votes cast −AAABBAABABABAABBAAABAABBAABABABAABAABBAABABAABBAAAFor the order AABAB, the tally of the votes as the election progresses is given below −CandidateAABABA12233B00112For each column the tally for A is always greater than the tally for B so the A is always strictly ahead of B. For ... Read More

All combinations of strings that can be used to dial a number in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 07:43:50

133 Views

With respect of a given number, display or print all possible combinations of strings that can be implemented to dial the given number in a phone with the help of following pecifications.In the given phone, we can dial, 2 implementing A or B or C, 3 implementing D or E or F, ……………….8 implementing T or U or V, 9 implementing W or X or Y or Z, 1 implementing only 10 implementing 0.For example if 89, is the given phone number, the program should printTW, TX, TY, TZ, UW, UX, UY, UZ, VW, VX, VY, VZ#include #include ... Read More

Some Interesting Observations about C/C++ Ternary Operator

Arnab Chakraborty
Updated on 29-Jan-2020 07:29:59

309 Views

We know that ternary operator is implemented instead of if..else clause. It is denoted by ?: . '?' symbol is equivalent to if part and ':' is equivalent to else part. The following 3 programs explain some interesting observation in case of ternary operator.The following program is able to compile without any error. Ternary expression’s return type is expected to be float (as that of exp2) and exp3 (i.e. literal zero - int type) is able to implicitly convert to float.#include using namespace std; int main(){    int test1 = 0;    float fvalue = 3.111f;    cout

Advertisements