answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

What is the difference between a recursive and an explicit formula?

a recursive formula is always based on a preceding value and uses A n-1 and the formula must have a start point (an A1) also known as a seed value.

unlike recursion, explicit forms can stand alone and you can put any value into the "n" and one answer does not depend on the answer before it. we assume the "n" starts with 1 then 2 then 3 and so on

arithmetic sequence: an = a1 + d(n-1) this does not depend on a previous value

Calling a function from switch in C?

Yes, you can call a function from within a switch statement in C.

switch (i) {

case 0: function1(i); break;

case 1: function2(i); break;

default: function3(i); break;

}

When the function returns, you will still be in the switch statement.

What is difference between wait and sleep and delay in C plus plus?

It depends on the particular library implementation. It is not a C++ specific question. As far as C++ is concerned, it is just a function call, just like a call to printf or even exit is a function call.

One could be a call to wait for an event.

One could be a call to sleep for a specified period of time.

One could be a call to burn CPU cycles for a specified period of time.

Again, it all depends on the library implementation, and you need to read the documentation for your library to answer this one.

How many nodes are there in the nth of a binary tree?

If N>1, there are (2N-1) - (2N-1-1), otherwise, 1 nodes in the Nth level of a balanced binary tree.

How do you write a c program to determine if a matrix is symmetric or not?

A matrix is symmetric when it is a perfect square and the transpose of the matrix is equal to the original matrix. The implementation is reasonably straightforward and can be done without actually creating the transposed matrix. We simply imagine a dividing line through the main diagonal (top-left to bottom right) and compare the corresponding elements on each side of that diagonal.

bool is_symmetric (int* a, int rows, int cols) {

if (rows!=cols) return false;

for (int row=0, row

for (int col=row+1; col

if (a[row][col] != a[col][row]) return false;

return true;

}

This works because for every element a[row][col] in a square matrix, the corresponding element on the other side of the main diagonal must be a[col][row]. In other words, we simply transpose the subscripts (hence it is called the transpose).

Consider a 4x4 matrix of hexadecimal values:

0 1 2 3

4 5 6 7

8 9 A B

C D E F

The main diagonal line is identified as elements {0, 5, A, F}. Element {7} lies above this line and it corresponds with element {D} below the line. Element {7} is identified with the subscript [1][3] while element {D} is identified with the subscript [3][1].

Note that the inner loop which traverses the columns always starts at col=row+1. This ensures that we always start with the first element after the diagonal element in the current row, and traverse through the remaining elements of that row. In other words, elements in [row][col] are always in the upper-right of the matrix, above the main diagonal. Meanwhile, the corresponding transpose, element [col][row], lies in the lower-left of the matrix, below the main diagonal. There is no need to test the entire array, traversing every column of every row, because there's no point in testing elements on the diagonal itself (we'd be comparing each element to itself and its given that an element is always equal to itself), and there's no point in comparing the lower-left elements to the upper-right elements when we've already performed the reverse comparison. After all, if X==Y then it follows that Y==X because equality is a transitive operation (the result is the same regardless of which side of the operator we place the operands).

Note that in order to replace a square matrix with its transpose, we simply swap the corresponding elements unless the matrix is symmetrical (because, by definition, a symmetrical matrix is equal to its own transpose):

void transpose (int* a, int rows, int cols) {

if (rows!=cols is_symmetric (a, rows, cols)) return;

for (int row=0, row

for (int col=row+1; col

swap (&a[row][col], &a[col][row]);

}

Why is compiling necessary?

Compilers are only necessary for programmers; ordinary users do not require them. A compiler is a program which converts a high-level source input into a lower-level source output, reducing the amount of abstraction. In most cases the output is native machine code and/or an assembly source, however there are some exceptions, such as the Java compiler which outputs Java byte code, and cross-language compilers such as C++ to C compilers.

Machine's do not understand either high-level source code or low-level assembly code, they only understand their own native machine code. Thus conversion to machine code is necessary. Once converted to machine code, no further translation is necessary.

Assembly sources must be converted using an assembler, however assembly is a machine-dependent language (it is non-portable). High-level languages are generally portable and are either compiled or interpreted. Interpretation requires a runtime program to perform the conversion while the source code is executing and performs poorly compared to a native machine code program. Java is both compiled and interpreted. That is; Java source code compiles to Java byte code which is suitable for interpretation by the Java virtual machine.

It is not possible to compile a low-level source to produce a high-level output. For example, you cannot convert C to C++ using a compiler, just as you cannot convert assembly language to C. Compilers can only reduce the amount of abstraction in the source code, not increase it. If you want to add more abstraction, you need to do so manually.

Difference between cin and scanf?

the getchar function waits the user hit a key followed by return key. Upon the return key hitted by the user the function returns the key. But the scanf can be used for various & different user entered data including text, integer, float and so on. in spite of getchar the delimeter keys for scanf function are tab, space and return key; so when a space entered by the user in the input the scanf will end the input and waits user enter the return key. You must take in mind that just the fragment of input that is behind these delimeters will be considered as legal input for the scanf and the remaninder will be escaped.

What is linker error?

An error detected (or perhaps caused) by the linker. Examples: unresolved symbol, duplicated symbol.

How do you get the gcf in c programming language?

Algorithm: to find HCF of two nos a, b 1. Find larger of two and let it l, smaller = s 2. divide l by s and find qotient (q) & remainder(r) 3. if r is 0 then s is the hcf 4. put l=s, s=r and go to step 2 int a, b; int l,s,q,r; if (a>b) {l=a;s=b;} else {l=b;s=a;} do {q= l/s; r=l%s; if (r != 0) {l=s;s=r} } while (r != 0); hcf=s; /* this variable to be output or returned as a function value as per programmer's convenience */

Which key element will be best for merge sort and why?

There is no key element in a merge sort. Unlike quick sort which requires a key element (a pivot) to recursively divide a subset into two subsets, merge sort simply divides a subset into subsets of 1 element and merges adjacent subsets together to produce sorted subsets. When there is only one subset remaining, the subset is fully sorted.

Who is the Str ongest DC Character?

Determining the strongest DC character can be subjective, as it often depends on the context and storyline. However, many consider Superman, especially in his most powerful forms, to be one of the strongest due to his incredible abilities like super strength, speed, and flight. Additionally, characters like Doctor Manhattan and the Presence, who possess omnipotent powers, could also be seen as the strongest in terms of sheer capability. Ultimately, strength in the DC universe can vary greatly depending on the narrative.

What is a design data type?

A design data type is a specialized data structure used in software development to represent complex data models or system designs. It encapsulates both the data and the operations that can be performed on that data, enabling more intuitive and organized programming. Common examples include classes in object-oriented programming or user-defined types in languages like Ada and C. Design data types help improve code readability, maintainability, and reusability.

What is the difference between program and programming?

define program

i. program means set of instruction which are required for a particular type of task is called program

ii. set of instruction or commands which are given for the computer to do different activity or jobs or works is called program

define programming

the process of creating/modifying a program; some people's job, others' hobby

Who is John c?

The most amazing person in the world. And his friend is Justin, Gerell, and Kristie :)

What is meant by TSR in C?

It means Terminate-Stay-Resident. A TSR is a program that remains in memory when the program ends.

What is the structure of the katipunan?

Structure of Katipunan

The structure of Katipunan reveals that it was greatly influenced by Masonry as to initiation rites, and by Rizal's La Liga Filipina as to organization. Structurally, the society had 3 governing bodies- the Kataastaasang Sanggunian or Supreme Council, the Sangguniang Bayan or Provincial Council and the Sanggyniang Balanggay or Popular Council. Kataastaasang Sanggunian is the highest governing bodyof society. Sangguniang Bayan and Sangguniang Balanggay represents the province and municipality or town.

Judicial matters affecting the members of the society were referred to as sort of court known as the Sangguniang Hukuman or Judicial Council. During its existence, the Judicial Council had not passed the death sentence on any member. But a secret chamber, composed of Bonifacio, Jacinto, Valenzuela srntenced some members to be expelled for having allegedly violated the secrets of the society.