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

Dry run table in flow-chart?

/* my second program in C++ with more comments */ #include <iostream> using namespace std; int main () { cout << "Hello World! "; // prints Hello World! cout << "I'm a C++ program"; // prints I'm a C++ program return 0; }

How to write a j in Spanish?

The letter is the same as in English "j". It is called "hota", an is pronounced like a somewhat gutteral English "h".

Write a program to delete an element from the kth position of the given unsorted array?

#include

#include

int main()

{

int i,j,item,n,a[10],u,k;

printf("enter the limit\n");

scanf("%d",&n);

if(n>=10)

{

printf("Array exceed limit .correct the limit value below 10 \n");

}

else

{

printf("enter the inserted element");

scanf("%d",&item);

printf("enter the position\n");

scanf("%d",&k);

if(k<=nk<=10)

{

printf("enter the terms\n");

for(i=1;i<=n;i++)

{

scanf("%d",&a[i]);

}

printf("inserted list\n");

for(i=1;i<=n;i++)

{

printf("%d\n",a[i]);

}

printf("inser list\n");

j=n;

while(j>=k)

{

a[j+1] =a[j];

j=j-1;

}

a[k]=item;

for(i=1;i<=n+1;i++)

{

printf("%d\n",a[i]);

}

}

else

{

printf("postion given in below limit not equal to \n");

}

}

getch();

return 0;

}

// program by choudhary yogesh malik

Is fork is an process?

The fork() library function makes a copy of the calling process. The original copy continues with a return value of the process ID of the new process, while the new copy continues with a return value of zero. If there is an error, the original process continues with a return value of -1. So, the answer is that fork is a process creation function.

Differentiate data processing from information?

Definitions We need to differentiate between data, information, intelligence and knowledge ♦ Data are symbolic depictions of facts (e.g the display on a thermometer, or a ten year time series reflecting GDP, balance of payments and exchange rate performance). ♦ Information is data set in particular context (e.g the proposition: "It was 30 degrees Celsius at Cap d'Antibes at 11:00 a.m on 3 August 1999.", or "The south-east Asian economies grew rapidly between 1985 and 1995."). ♦ Intelligence is the processes and the products that lead to understanding and taking decisions related to reality. ♦ Knowledge is the product of thinking, the connection of information in a logical-functional way. Knowledge allows us to explain or give reasons for phenomena, and to predict future events. Definitions We need to differentiate between data, information, intelligence and knowledge ♦ Data are symbolic depictions of facts (e.g the display on a thermometer, or a ten year time series reflecting GDP, balance of payments and exchange rate performance). ♦ Information is data set in particular context (e.g the proposition: "It was 30 degrees Celsius at Cap d'Antibes at 11:00 a.m on 3 August 1999.", or "The south-east Asian economies grew rapidly between 1985 and 1995."). ♦ Intelligence is the processes and the products that lead to understanding and taking decisions related to reality. ♦ Knowledge is the product of thinking, the connection of information in a logical-functional way. Knowledge allows us to explain or give reasons for phenomena, and to predict future events. Definitions We need to differentiate between data, information, intelligence and knowledge ♦ Data are symbolic depictions of facts (e.g the display on a thermometer, or a ten year time series reflecting GDP, balance of payments and exchange rate performance). ♦ Information is data set in particular context (e.g the proposition: "It was 30 degrees Celsius at Cap d'Antibes at 11:00 a.m on 3 August 1999.", or "The south-east Asian economies grew rapidly between 1985 and 1995."). ♦ Intelligence is the processes and the products that lead to understanding and taking decisions related to reality. ♦ Knowledge is the product of thinking, the connection of information in a logical-functional way. Knowledge allows us to explain or give reasons for phenomena, and to predict future events.

What are the words that make up a high level programming language called?

Some languages have specific terms, however keyword or reserved word is the general terminology we use when referring to a programming language's primary vocabulary. That is; words that cannot be used as identifiers. However, some languages also have contextual keywords. For instance, C++ has final and override contextual keywords. These can be used as both identifiers and keywords, depending on the context. The only reason for this is that people were using these words as identifiers before they were introduced to the language (in C++11) and making them actual keywords would have broken a lot of older code.

Wap in c plus plus to find out the string is palindrome or not in?

use the strrev() function on the given string and compare with original string.If both are equal they are palindromes else not.

Is sql used in c plus plus and cobol language?

Not as part of the formal language, but you can use SQL in various languages, including C++ or Cobol, if you have an appropriate precompiler that allows you to interface with the desired DBMS, be it Oracle, DB2, or whatever. You can also use an interface, such as OCI, if you want. Again, none of these methods are strictly a part of the language.

How do you write a c program for to replace a character of string either fro mbeginning or ending or at specified location?

The standard C library includes two simple utilities to find the first or last occurance of a given character within a given string, strchr() to search from the start and strrchr() for the reverse start from the end.

Subject to the chosen search direction, you could use one of these two simple API. Both return a pointer to the location of the matching character within the string, or NULL if no such character is found.

Note that this approach assumes a mutable string, a string stored in writeable memory. A string literal is a constant string and not generally mutable (even though some compilers are very casual about this). That is, strchr("the quick brown fox", 'q') will return a pointer to the first 'q', but since the string is a string of constant characters, you shouldn't use the pointer to change the letter found.

To search and modify, you'd use string of variable characters, such as one allocated with the malloc() or strdup() standard API, or one created as a char array.

How can you convert binary number into decimal number using g plus plus compiler?

The following code will convert any number in any base to any other base, from binary to hexadecimal, and everything inbetween.

#include<iostream>

#include<string>

#include<sstream>

typedef unsigned long long ull;

typedef unsigned long ul;

const std::string symbols="0123456789abcdef";

std::string inputvalue(ul base)

{

using namespace std;

string value;

while(1)

{

cout<<"Enter a positive value : ";

string s;

getline(cin,s);

if(s.size())

{

for(string::iterator i=s.begin();i!=s.end();++i)

if(*i>='A' && *i<='Z')

*i+=32;

string actual = symbols.substr(0,base);

if(s.find_first_not_of(actual)!=string::npos)

{

cout<<"The value you entered is invalid for the base.\n"

<<"Please enter another value.\n"<<endl;

continue;

}

value=s;

break;

}

}

return(value);

}

ul inputbase(std::string prompt)

{

using namespace std;

ul result=0, min=2, max=16;

while(1)

{

cout<<prompt.c_str()<<" ["<<min<<".."<<max<<"] : ";

string s;

getline(cin,s);

if(s.size())

result=stoul(s,0,10);

if(result<min result>max)

cout<<"The base must be in the range "

<<min<<".."<<max<<"\n"

<<"Please enter another base.\n"<<endl;

else

break;

}

return(result);

}

ull base2dec(std::string value,ul base)

{

ull col=1, num=0;

for(std::string::reverse_iterator i=value.rbegin(); i!=value.rend(); ++i)

{

num+=symbols.find(*i,0)*col;

col*=base;

}

return(num);

}

std::string dec2base(ull dec,ul base)

{

using namespace std;

int len=1;

ull tmp=dec;

while(tmp/=base)

++len;

string value("0",len);

while(dec)

{

value[--len]=symbols[dec%base];

dec/=base;

}

return(value);

}

int main()

{

using namespace std;

ul base=inputbase("Enter the base of the value");

string value=inputvalue(base);

ul newbase=inputbase("Enter the base to convert to");

value=dec2base(base2dec(value,base),newbase);

cout<<"New value:\t"<<value.c_str()<<endl;

return(0);

}

What is meant by throw command in c plus plus?

A 'throw' statement throws an exception when it is generated within a try block. The exception is then caught by the corresponding catch block. For example,

void somefn()

{

float m, n;

try

{

cin>>m>>n;

if (n == 0)

throw(n);

else

cout<<(m/n);

}

catch (float x)

{

cout<<"Division by zero not possible";

}

}

Why does an interpreter not convert source code into machine language?

A traditional interpreter interprets the source code instructions at runtime, and executes them directly. Compiling the instructions into machine code is not part of of a traditionally interpreter's design.

However, many modern interpreters work differently from traditional interpreters. In the traditional concept, an interpreter would digest the exact source code instructions at runtime, parsing "if" and "else" and so forth.

Most modern interpreters compile (!) the source code into code fit for a virtual machine (sometimes called hypercode or p-code). This virtual machine is implemented as an interpreter, which interprets and executes the stream of hypercode instructions at runtime. This is more efficient, since the interpreter doesn't have to handle surplus input (such as comment), and can rely on the input to be pre-validated for syntactic and, to some extend, semantic correctness.

Most modern virtual machine interpreters support another compilation step at runtime, typically called just-in-time compilation or JIT for short. With JIT, the virtual machine translates portions of the hypercode into real machine code at runtime, thus improving execution speed for repeatedly executed code.

Popular programming languages such as Java or the .NET languages all work on this principle.

What is Repetition and its types data structure and algorithm?

In programming, there are two types of repetition: iterative and recursive. Both are a type of loop.

Iterative loops have three general types:

  1. while loop
  2. do loop
  3. for loop

The while loop is the simplest loop. It tests a conditional expression at the start of each iteration. If the expression holds true, the body of the loop executes for one iteration. The loop continues to iterate until the expression does not hold true.

The do loop is similar to a while loop except the conditional expression is placed at the end of each iteration. Thus the body of the loop will always execute at least once. A do loop is also known as a do until loop.

The for loop is typically used to perform counted iterations. Unlike the while and do loops, a conditional expression is optional (evaluating true when omitted). In addition, a for loop can initialise a variable upon first entry to the loop and can perform an action at the end of each iteration. All clauses of the for loop are optional.

Within the body of any iterative loop, the programmer can also use additional conditional expressions in conjunction with continue, break, return or goto statements. A continue statement skips the remaining portion of the loop and begins a new iteration (testing the controlling conditional expression beforehand). A break exits the loop. A return exits the function and returns control to the caller. A goto jumps to the named label. Although goto statements are frowned upon, a goto is the most efficient way of breaking out of a nested loop (a loop within a loop).

Recursive loops make use of recursive function calls. That is; a function that calls itself. Recursive functions are typically used in conquer-and-divide algorithms where a large problem can be restated as one or more smaller problems of the same type, until the problem is small enough that it can be processed. This results in one or more small solutions that combine to form the larger solution.

To better explain the concept, let us consider the naturally recursive function to calculate the factorial of a number. Factorials determine the number of permutations within a given set. That is, a set of {abc} has 3 elements and therefore 6 permutations: {{abc},{acb},{bac},{bca},{cab},{cba}}. For any given set of n elements, the number of permutations is the product of all positive integers in the closed range [1:n]. Thus the first few factorials are as follows:

f(0) = 1

f(1) = 1

f(2) = 1x2 = 2

f(3) = 1x2x3 = 6

f(4) = 1x2x3x4 = 24

Note that 0! denotes the empty set which has one permutation, the same as a set of 1. However, for all values n>1 we can see that the result is the same as saying:

f(n) = f(n-1) x n

In other words, it is a recursive function. The end point is reached when n is less than 2 thus we can program this function as follows:

unsigned f (unsigned n) {

if (n>1)

return f(n-1)*n;

return 1;

}

If n were 4, then the first instance of the function will be invoked as f(4). This in turn invokes f(3), f(2) and finally f(1) which returns 1 to f(2), which returns 2 to f(3) which returns 6 to f(4) which finally returns 24 to the caller.

[It should be noted that factorials produce huge numbers and are only practical for calculating f(12) using 32-bit integrals and f(20) using 64-bit integrals. If you need larger factorials, you must use a user-defined type capable of handling larger integrals.]

Unlike an iterative loop which simply cycles from one state to the next never to return to a previous state, a recursive loop maintains state between calls and revisits that state upon each return. This technique is the essence of all backtracking algorithms and is made possible by automatically pushing local variables onto the call stack with each function call and popping those same variables upon return, along with the result of the call. We also refer to this as "winding" and "unwinding" the stack, analogous to winding a clock spring with each recursion and unwinding with each return.

With each call to the function, we increase the depth of recursion. With each return, we decrease the depth of recursion. If we do not provide an end point in our function, the depth of recursion will be such that all stack space will eventually be consumed and our program will crash. However, a recursive function may increase and decrease its depth of recursion several times over during a single calculation and this is the essence of divide-and-conquer algorithms such as the quicksort algorithm. That is, each call of the function divides an unsorted set into two subsets around a single pivot (or several contiguous pivots of the same value). The pivot is in the correct place with respect to the two subsets, but those subsets are still unsorted. Thus quicksort is recursively applied to each of these subsets in turn. Eventually a subset will have fewer than 2 elements which represents the endpoint for that particular recursion. When all subsets have fewer than 2 elements, the entire set is sorted.

Given that the two subsets in a quicksort may not be of equal size, the larger subset will inevitably incur more recursions than the smaller subset. Thus it pays to recurse over the smaller subset and make a tail call for the larger one. A tail call is where the final statement in a function is a recursive call to the same function. Given that state does not need to be maintained for a tail call (because it is the last statement of the function), the same instance of the function can be invoked (with modified parameters) rather than going to the expense of making an otherwise unnecessary function call. Modern compilers generally include tail-call optimisation to take advantage of this.

Although iteration can be more efficient than recursion, even with naturally recursive functions, modern compilers are capable of inline expanding recursive functions to a certain degree (or rather depth), particularly if the depth can be calculated at compile time and the increased code size does not adversely affect performance. If the depth cannot be calculated in advance, inline expansion can still be achieved up to the predefined depth with a standard recursive call for any additional recursions that may be required at runtime. That being the case there is generally no reason to try and create an iterative solution to what would otherwise be a naturally recursive algorithm.

What is indicator variable?

It is a variable that takes the value 1 if the characteristic under consideration is present and 0 otherwise.

What is the difference between using angular brackets in C language and double quotes in Cpp language to enclose header files?

When you includes any header file using "" that time compiler try to locate this file first from your program's local directory and then from library. But if you include the .h file using <> then compiler assumes you are including some library file.

Three kinds of iteration structures in c?

Iteration structures are also called as loops. The following are the loops available in c.

1. for (initialization; condition; increase/decrese) statement

2. while (expression) statement

3. do statement while (condition)

Turbo c program code for asterisk pyramid pattern?

void main()

{

char userid[]="user",password[]="password",p[15],u[15];

int n=1,a,b;

printf("\nEnter username and password below (You have only three chances to enter)");

getch();

while(n<=3)

{

system("cls");

printf("\nUsername: ");

scanf("%s",u);

printf("\nPassword: ");

scanf("%s",p);

What is theprogram to generate n Fibonacci numbers n please explain each statement?

Program to Print Fibonacci Series

#include
#include
void main()
{
int n,i,f1=0,f2=1,f3;
clrscr();
printf("Enter n number : ");
scanf("%d",&n);
printf("%d\t%d",f1,f2);
for(i=3;i<=n;i++)
{
f3=f1+f2;
printf("\t%d",f3);
f1=f2;
f2=f3;
}
getch();
}

Output :

Enter n number : 10
0 1 1 2 3 5 8 13 21 34

How to determine an almost complete binary tree is a heap?

A binary heap is defined as follows: # It it an "almost" complete binary tree. That is, the bottom level of a heap of height h is partially filled from left to right, and may only have from 1 to 2h nodes. This may make some of the nodes at level h-1 into leaf nodes. So a binary heap of height h may have anywhere from 2h to 2h+1-1 nodes. # It satisfies the heap property. Each node has some ordered value associated with it, like a real number. The heap property asserts that a parent node must be greater than or equal to both of its children. A binary heap is easily represented using an array, let's call it A[1..length(A)]. The size of the heap will be called heap-size(A) (obviously heap-size(A) <= length(A)). We can use the first element of the array, element #1, as the root of the heap. The left child of array element i is at element 2i, and the right child is at element 2i+1. Also, the parent of an element at node i is at half of i. An element can tell whether it is a left or right child simply be checking whether it is even or odd, respectively. We define these "algorithms" for finding indices parents and children in pseudocode: Parent (i) return floor (i / 2) Left (i) return 2 * i Right (i) return 2 * i + 1 You can tell if an array element i is in the heap simply by checking whether i <= heap-size(A). Note: this scheme doesn't work in general with binary (possibly incomplete) trees, since representing leaf nodes at depths less than the height of the tree minus 1 isn't possible, and if it were, it would waste space. This representation of an almost complete binary tree is pretty efficient, since moving around the tree involves multiplying and dividing by two, operations that can be done with simple shifts in logic, and adding one, another simple instruction. Asymptotically speaking, each of the heap node access functions above consume O(1) time. ghjghjhjk hjkjk