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

Write a program in c language to print some message on the screen with out using printf?

you can put the printf function inside a if() so that you need not use semicolons. for eg to print my name, if(printf("My Name is Maheedharan")) {} this will work. try this out...

What are reallife applications of graphs in data structures?

Applications of graph theory are primarily, but not exclusively, concerned with labeled graphs and various specializations of these.

Structures that can be represented as graphs are ubiquitous, and many problems of practical interest can be represented by graphs. The link structure of a website could be represented by a directed graph: the vertices are the web pages available at the website and a directed edge from page A to page B exists if and only if A contains a link to B. A similar approach can be taken to problems in travel, biology, computer chip design, and many other fields. The development of algorithms to handle graphs is therefore of major interest in computer science. There, the transformation of graphs is often formalized and represented by graph rewrite systems. They are either directly used or properties of the rewrite systems(e.g. confluence) are studied.

A graph structure can be extended by assigning a weight to each edge of the graph. Graphs with weights, or weighted graphs, are used to represent structures in which pairwise connections have some numerical values. For example if a graph represents a road network, the weights could represent the length of each road. A digraph with weighted edges in the context of graph theory is called a network.

Networks have many uses in the practical side of graph theory, network analysis (for example, to model and analyze traffic networks). Within network analysis, the definition of the term "network" varies, and may often refer to a simple graph.

Many applications of graph theory exist in the form of network analysis. These split broadly into three categories. Firstly, analysis to determine structural properties of a network, such as the distribution of vertex degrees and the diameter of the graph. A vast number of graph measures exist, and the production of useful ones for various domains remains an active area of research. Secondly, analysis to find a measurable quantity within the network, for example, for a transportation network, the level of vehicular flow within any portion of it. Thirdly, analysis of dynamical properties of networks.

Graph theory is also used to study molecules in chemistry and physics. In condensed matter physics, the three dimensional structure of complicated simulated atomic structures can be studied quantitatively by gathering statistics on graph-theoretic properties related to the topology of the atoms. For example, Franzblau's shortest-path (SP) rings. In chemistry a graph makes a natural model for a molecule, where vertices represent atoms and edges bonds. This approach is especially used in computer processing of molecular structures, ranging from chemical editors to database searching.

Graph theory is also widely used in sociology as a way, for example, to measure actors' prestige or to explore diffusion mechanisms, notably through the use of social network analysis software.

Likewise, graph theory is useful in biology and conservation efforts where a vertex can represent regions where certain species exist (or habitats) and the edges represent migration paths, or movement between the regions. This information is important when looking at breeding patterns or tracking the spread of disease, parasites or how changes to the movement can affect other species.

What is compaction in data structure?

The process of moving all marked nodes to one end of memory and all available memory to other end is called compaction. Algorithm which performs compaction is called compacting algorithm.

What are the basic input and output of c and c plus plus?

That is STANDARD input and STANDARD output.

By default, standard input is the keyboard, and standard output is the screen. Standard I/O is set by the operating system, though it may be redirected by script invocation or system commands within the C/C++ program itself. You could, for instance, set standard output to a printer or a file in lieu of a screen.

You should also Google Standard Error.

What is ASCII value of 0?

The ascii value of zero - is 48.

What are the various operations that can be performed on a queue?

In queue insertion takes place on rear end and deletion takes place on front end.

INSERTION(QUEUE,N,FRONT,REAR,ITEM) :QUEUE is the name of a array on which we are implementing the queue having size N.

view comlete ans at

http://mcabcanotes.in/algorithm-to-perform-insertion-and-deletion-in-a-queue/

How can a stack determine if a string is a palindrome?

foreach char in string

push on to stack

create new string

foreach char in string

pop off and add to end of new string

if new string equals old string

palindrome

else not palindrome

//when you pop off the stack, the characters come off in reverse order, thus you have reversed the original string

What is void rate?

Void ratio is defined as the ratio of the volume of the void space compared to the volume of the solid particles.

Why c language is named c?

C comes from B & B comes from BCPL........... TO overcome the problems of BCPL they developed B (First char of BCPL)....& B also has some disadvantages so they go for next level i.e, B's next Letter .........:::::::C ..........then v called it as C language. C comes from B & B comes from BCPL........... TO overcome the problems of BCPL they developed B (First char of BCPL)....& B also has some disadvantages so they go for next level i.e, B's next Letter .........:::::::C ..........then v called it as C language.

Two stacks in one array?

/*implementing two stacks in 1 array*/ #include #include #include int size,top1=-1,top2,a[100]; void push(); void pop(); void peep(); void main() { int i,ch; char c='y'; clrscr(); printf("\Enter size:"); scanf("%d",&size); top2=size; while(c=='y') { clrscr(); printf("\n ###### MENU #####\n"); printf("\n1: push"); printf("\n2: pop"); printf("\n3: peep"); printf("\n4: exit") ; printf("\n Enter choice:"); fflush(stdin); scanf("%d",&ch); switch(ch) { case 1:push(); break; case 2:pop(); break; case 3:peep(); break; case 4:exit(0); default:printf("\n wrong choice"); } printf("\n Another operation(y/n):"); fflush(stdin); scanf("%c",&c); } exit(0); getch(); } void push() { int item,ch; if(top1+1==top2) { printf("stack is full "); printf("\n cant push "); } else { printf("\nEnter item to be inserted:"); scanf("%d",&item); printf("\n enter choice(1 for stack1 else stack2):"); scanf("%d",&ch); if(ch==1) { top1++; a[top1]=item; } else { top2--; a[top2]=item; } } } void pop() { int ch; printf("\n Enter from which stack u want to pop(1 for stack1/else stack2):"); scanf("%d",&ch); if(ch==1) { if(top1==-1) printf("\n cant delete from stack 1 its empty"); else printf("\n item deleted is:%d" ,a[top1--]); } else { if(top2==size) printf("\n cant delete from s2its empty"); else printf("\n item deleted is: %d" ,a[top2++]); } } void peep() { int i; printf("\n stck 1:" ); for(i=0;i=top2;i--) printf(" %d",a[i]); }

Program to find the second largest number in a given set of numbers using arrays without sorting?

Improved Solution to this problem would be able to find any first, second, third.. largest number...

here it is, in Java:

class Sam {

public static void main(String args[]) {

int[] nums = new int[] { 445, 43, 1045, 110, 209, 109, 33, 24, 1566 };

int cnt = 0;

int size = nums.length;

int temp;

int largest = 0;

int secondLargest = 0;

int thirdLargest = 0;

int fourthLargest = 0;

int fifthLargest = 0;

//the logic rests here

while (cnt < size) {

temp = nums[cnt];

if (temp > largest) {

secondLargest = largest;

largest = temp;

} else if (temp > secondLargest) {

thirdLargest = secondLargest;

secondLargest = temp;

} else if (temp > thirdLargest) {

fourthLargest = thirdLargest;

thirdLargest = temp;

} else if (temp > fourthLargest) {

fifthLargest = fourthLargest;

fourthLargest = temp;

} else if (temp > fifthLargest) {

fifthLargest = temp;

}

cnt++;

}

System.out.println("largest:" + largest);

System.out.println("secondLargest:" + secondLargest);

System.out.println("thirdLargest:" + thirdLargest);

System.out.println("fourthLargest:" + fourthLargest);

System.out.println("fifthLargest:" + fifthLargest);

}

}

// Regards,

// SwapniM

// mail me at: swap.masane@gmail.com

#include

using std::cin;

using std::cout;

using std::endl;

double maxFirst(const double data[], intindex);

double maxSecond(const double data[], intindex, double maxNumber1);

double sum(double max1, double max2);

int main()

{

double myArray[] = {

1.0,

4.6,

32.1,

9.7,

41.2,

41.3,

343,

23,

566.02,

345.8,

675.5,

654.4

};

int arraySize = (sizeof myArray)/(sizeof myArray[0]);

cout << "Your array is: ";

for (int k = 0; k < arraySize; k++)

{

cout << endl << myArray[k];

}

double max1 = maxFirst(myArray, arraySize);

double max2 = maxSecond(myArray, arraySize, max1);

cout << endl << "First biggest number is: " << max1;

cout << endl << "Second biggest number is: " << max2;

system("PAUSE");

return 0;

}

double maxFirst(const double data[], intindex)

{

double maxNumber1 = data[0];

for (int i = 0; i < index; i++)

{

if (maxNumber1 < data[i])

{

maxNumber1 = data[i];

}

}

return maxNumber1;

}

double maxSecond(const double data[], intindex, double maxNumber1)

{

double maxNumber2 = data[1];

for (int j = 0; j < index; j++)

{

if (data[j] == maxNumber1)

{

continue;

}

else if (maxNumber2 < data[j])

{

maxNumber2 = data[j];

}

}

return maxNumber2;

}

What are object files in c?

Object files are intermediate files generated when an application is constructed from source code. In a classic compile-assemble-link toolchain, the compiler translates (C language) source code into assembly language output. The assembler translates this intermediate assembly source into a binary form known as object code. Files containing object code often have a .o or .obj file name extension and are generally called object files. The linker takes the object files and combines them into the complete executable.

While many modern tools hide the individual steps, or even integrate compilation and assembly into one, most (all?) compilers generate object files.

Why are Cobol and Fortran are case sensitive?

The languages are not case sensitive in most implementations. However, Fortran versions from F77 forward allow the use of lower-case letters in statements; the compiler simply translates them all to upper-case before processing.

Case sensitivity is a contentious item among programmers. Typing in mixed, INsensitive case is a lot more readable, but programming with case sensitivity can be a recipe for disaster. For example, it's a lot easier to read a name called SetOutputStage than SETOUTPUTSTAGE or setoutputstage. But if the compiler is case sensitive, all it takes is one fumblefingered letter to create 2 variables - e.g. SetOutputStage and SetOutputstage, which are virtually indistinguishable to the eye!

What is the purpose of a getchar function?

The getchar() function gets a single character from stdin.

Here is a very basic example:

#include <stdio.h>

int main() {

char ch;

do {

ch = getchar();

putchar(ch);

} while (ch != ';');

return 0;

}

It reads from data you input and prints it again of the screen after you press key. It works until it reaches ";" symbol.

The getchar() function is equivalent to getc(stdin).

What is derived data?

Derived data is data that is copied or enhanced from operational data sources into an informational database. This is in the information catalog center.

C with the line over it mean with?

A lower case c with a horizontal line above it means "with". This character might be seen as instructions for medication "should be taken "with" food"

What is type compatibility in c?

Compatible data types are data types that are intrinsically the same. For instance,

typedef int myint;

myint x = 0x7fffffff;

int y = x; // x and y are the same type, so assignment is permitted.

int * p = &x; // compatible, p points to x.

*p = y; // compatible, but y is a value, not a memory address.

short z = x; // compatible, but z will be truncated to -1.

z is -1 because x appears in memory in reverse order: 0xffffff7f. Since z is only two bytes in length it is equal to 0xffff after assignment, which equates to -1.

Write a C program to find GCD of 2 numbers using non-recursion?

One way to find the GCD (Greatest Common Divisor) of two numbers is Euclid's method. The following program demostrates this, without using recursion. The third number printed is the GCD of the first two. The highlighted lines are the core of the algorithm.

#include

int GcdByEuclid (int a, int b) {

if (a < 0 b < 0) return -1;

while (a > 0 && b > 0) if (a > b) a -= b; else b -= a;

if (a == 0) return b; else return a;

}

int main (int argc, char *argv[]) {

int a, b;

if (argc < 3) {

fprintf (stderr, "Usage: gcd a b\n");

return 1;

}

a = atoi(argv[1]);

b = atoi(argv[2]);

printf ("%d %d %d", a, b, GcdByEuclid (a, b));

return 0;

}

When is a doubly linked list appropriate?

Whenever you need constant time access to both the head and tail of the list and require bi-directional traversal of the list from any given node (not necessarily the head or tail).

With a singly linked list, the only way to perform a reverse traversal is through a recursive call. For instance, the following C function will print singly linked nodes in reverse order (the caller simply passes the head node to the function):

void print_reverse(node* current)

{

if( current )

{

print_reverse( current->next);

current->print(); }

}

While this works, for long lists there's a risk you might run out of stack space. This is because the head node (in the initial call) cannot print itself until the recursive call to the next node has returned, which it can't do until its recursive call returns, and so on until the recursion reaches the tail node. Only then will the recursions begin to unwind and the nodes can actually print themselves. Even if stack space isn't an issue, it's inefficient because you are effectively traversing the list twice; forwards to get to the tail and then backwards to do the actual printing.

With a doubly-linked list you simply traverse the list from the tail node to the head node in order to print them in reverse order:

void print_reverse(list& List)

{

node* current = List.tail;

while( 0 != current )

{

current->print();

current = current->prev; }

}

While not quite as concise as a recursive call, it is a good deal more efficient.

The other advantage is that should you have a reference to any node (whether the head, the tail or anything in between), you have the option to traverse forwards or backwards as you see fit. With a singly linked list you can only go forwards from a given node unless you used recursion to get to that node in the first place.

C program pointers to pointers examples?

Pointer to Pointer is a double pointer, denoted by (**). Pointer stores the address of the variable and pointer to pointer stores the address of a pointer variable and syntax can be given as int **ptr2ptr;

What is Dazzling Pointer in c plus plus?

The pointer that points to a block of memory that does not exist is called a dazzling pointer or wild pointer

Difference between member functions and static member functions?

c: A static function is visible only in the source file containing it. A static member is not defined. c++: A static function is visible only in the source file containing it. A static member variable is common to all instances of a class. A static member function is used to access static members.

Write an assembly language program to convert lowercase to uppercase?

inc bx ; next char.

loop upper_case

; int 21h / ah=09h - output of a string at ds:dx.

; string must be terminated by '$' sign.

lea dx, string+2

mov ah, 09h

int 21h

jmp start ; loop

; wait for any key press....

mov ah, 0

int 16h

null:

ret

Is printf keyword?

== == What is printf in c or prototype of printf with example

(q) What is prototype of printf function ? Explain each term.

Ans: Prototype of printf function is :

int printf( const char *format ,…)

Explanation of each term :

Parameter of printf function is :

(three continuous dots) : It is called ellipsis. It indicates the variable number of

arguments.

Example of ellipsis:

#include

void ellipsis(int a,...);

void main()

{

int a=5,b=10;

clrscr();

ellipsis(a,b);

getch();

}

void ellipsis(int a,...)

{

printf("%d ",a);

}

Output:5

So printf function can have any number of variables as an argument.