answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

Given a linked list of integers sorted in an ascending order and a pointer to a single node containing an integer write a C program that insert the node P in the linked list so that remains sorted?

InsertNode(NODE **q,int num)

{

NODE *r,*temp ;

temp = *q;

r= malloc(sizeof(NODE));

r->data = num;

//if it's fisrt node to be inserted

if ( *q == NULL num < (*q)->data)

{

*q = r ;

(*q)->link=temp;

}

else

{

while(temp)

{

if ( (num > temp->data) && (num < temp->link->data ) )

{

r->link = temp->link;

temp->link = r;

return;

}

temp = temp->link;

}

r->link = NULL;

temp->link = r;

}

}

How do I uninstall your operating system to install a new system?

There is no uninstaller for an operating system. To remove an OS, simply format the partition that holds the operating system. If you use a boot manager to choose between different operating systems the software should automatically detect missing operating systems for you.

Which translator translate low level language 1010111 to machines language?

Only assembly languages are generally considered low-level programming languages, so one could argue that there is only one low-level language.

However, there are as many assembly languages as there are processor models or families, as each processor family implements its own set of machine code instructions. Different manufacturers not only invent different mnemonics for similar machine code operations to suit conventions and hardware architecture (e.g. MOVE vs LOAD/SAVE), but also support different notations.

Therefore, conceptually, the assembly language is the only low level programming language. However, the standpoint of view of learning the language, or from that of tools to support the language, there are numerous assembly languages, thus numerous low-level languages.

Why Two pointers cannot be added in c language?

Because no-one knows what the sum of two pointers should be...
of course you can convert them to integers and then sum them, but why on earth would you do that?

C program to arrange 7 numbers in ascending order?

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,temp,a[7];

clrscr();

printf("Enter 7 integer numbers: \n");

for(i=0;i<7;i++)

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

for (i=0;i<7;i++)

{

for(j=i+1;j<7;j++)

{

if(a[i]<a[j])

{

temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}

}

printf("\n\nThe 7 numbers sorted in ascending order are: \n");

for(i=0;i<7;i++)

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

getch();

}

What is inter communication?

Inter-Cloud communication means communication between two cloud environments. The pairs can be Private-Private, Private-Public and Public-Public.


A classic example of inter cloud communication can be monitoring the performance of an application deployed on one cloud from another cloud.

1 Differentiate between Data and Information?

= How do you distinguish between data and information? = I THOUGHT DATA WAS THE OFFSPRING OF IMFORMATION, CONSIDERING DATA WOULD BE THE GATHERING OF INFORMATION. IT COULD SAID BE LIKE THIS: ALL THE INFORMATION YOU REQUESTED DATA ON HAS BEEN STORED IN YOUR HARD DRIVE, THEIR THE TWO TOGETHER IN ONE SETENCE. ON THE OTHER HAND DATA.. INDUCTIVE REASONING: A TREMENDOUS SEA OF INFORMATION.. YOU HAVE TO SEE ENOUGH, TO REMEMBER ENOUGH INFO TO PUT IT TOGETHER. I SAID THAT.... GENA

Flow chart for addition of two matrices?

For the resulting matrix, just add the corresponding elements from each of the matrices you add. Use coordinates, like "i" and "j", to loop through all the elements in the matrices. For example (for Java; code is similar in C):

for (i = 0; i <= height - 1; i++)
for (j = 0; j<= weidht - 1; j++)
matrix_c[i][j] = matrix_a[i][j] + matrix_b[i][j]


Program to check palindrome using recursion?

#include <stdio.h>

#include <conio.h>

void main()

{

int num,rev=0,m,r;

clrscr();

printf("enter any number");

scanf("%d",&num);

m=num;

while(num>0)

{

r=num%10;

rev=rev*10+r;

num=num/10;

}

if(rev==m)

printf("given number is palindrome");

else

printf("given number is not palindrome");

getch();

}

this is the answer.

What is the algorithm to convert miles to kilometers?

Multiply miles by 1.609344 to get kilometres:

double mile2km (double miles) { return miles * 1.609344; }

Multiply kilometres by 0.62137119 to get miles:

double km2mile (double km) { return km * 0.62137119; }

How do you display the contents of the memory address stored in an element of a pointer array?

Remember that a pointer is just a variable containing the memory address of another variable. A pointer to a pointer is no different, other than that the address contains the address of another pointer. You use the * indirection operator to get the value of the variable being pointed at (the address of the other pointer), and the ** indirection operator to get at the value pointed at by the other pointer.

The following example illustrates how to access the values of pointers to int via an array of pointers to those pointers.

The memory address and the value of every variable is displayed for the benefit of clarity.

#include <iostream>

using namespace std;

int main()

{

// Set up an array of pointers to pointers to int variables.

int X = 1, Y=2; // The actual variables.

int* pX = &X; // Pointers to those variables

int* pY = &Y;

int** pp[2]; // Array of pointers to those pointers.

pp[0] = &pX;

pp[1] = &pY;

// Print the address of all variables and their stored values:

cout << "Var\t&Address\tValue" << endl;

cout << "---\t--------\t-----" << endl;

cout << "X\t0x" << &X << "\t" << X << endl;

cout << "Y\t0x" << &Y << "\t" << Y << endl;

cout << "pX\t0x" << &pX << "\t0x" << pX << endl;

cout << "pY\t0x" << &pY << "\t0x" << pY << endl;

cout << "pp\t0x" << &pp << "\t0x" << pp << endl;

cout << endl;

cout << "Note that both &pp and pp return the same value: the address of the array." << endl;

cout << "pp is simply an alias for the memory allocated to the array itself, it is" << endl;

cout << "not a variable that contains a value. You must access the elements of the" << endl;

cout << "array to get at the actual values stored in the array." << endl;

cout << endl;

// Use the array elements to access the pointers and the values they point to:

cout << "Elem\t&Address\tValue\t\t*Value\t\t**Value" << endl;

cout << "----\t--------\t-----\t\t------\t\t-------" << endl;

cout << "pp[0]\t0x" << &pp[0] << "\t0x" << pp[0] << "\t0x" << *pp[0] << "\t" << **pp[0] << endl;

cout << "pp[1]\t0x" << &pp[1] << "\t0x" << pp[1] << "\t0x" << *pp[1] << "\t" << **pp[1] << endl;

cout << endl;

return( 0 );

}

What are the advantages of threads over processes?

Threads in distributed applications have the same benefits as in any other application: they allow you to perform multiple operations at the same time.

Specifically for distributed applications, the server will most definitely be multi-threaded so that it can communicate with all of the clients. The clients will also most likely have at least two threads: one for communication with the server and one for doing actual data processing.

Why might a programmer prefer the top-down approach to programming design?

some programmers think breaking the process into smaller parts allows them to better understand what the procedure being programmed does

How do you declare local and global variables in pseudo code?

Pseudocode is not a programming language (it's specifically intended for human interpretation), so there is no need to declare variables, you simply define them as and when you require them. For instance:

Let x = 42

Let y = x * 2

Who is the inventor of c plus plus language?

C was initially developed by Dennis Ritchie from 1969 to 1973. C++ was initially developed by Bjarn Stroustrup from 1979 (when it was known as C with Classes) to 1983 (when it was renamed C++). Both developers worked at Bell Labs at the time.

The binary number 11 would have a decimel equivelent of?

It depends.

If you are using unsigned numbers, then the following assumption is made:

0b11 = 0b00000011,

in which case the answer is;

2^1 + 2^0 = 2 + 1 = 3

If you are using signed numbers, than a binary number in the form 0b11 would be interpreted as negative because the leading bit is equal to 1. For signed numbers, the '1' in the leading bit is extended, thus:

0b11 = 0b11111111

In order to interpret this number, negate the number by flipping the bits and adding 1:

0b11111111

0b00000000 (bits flipped)

0b00000001 (added one)

The positive representation of 0b11111111 is equal to 0b00000001, which is equal to 1, thus

0b11 = 0b11111111 = -1

Give example of a language which uses more than one pass for compiling a program?

FORTRAN, Assembler, to name two. Effectively, any language that allows you to reference symbols before they are declared.

What is the backoff algorithm?

In a single channel contention based medium access control (MAC) protocols, whenever more than one station or node tries to access the medium at the same instant of time, it leads to packet collisions. If the collided stations tries to access the channel again, the packets will collide as the nodes are synchrozied in time. So the nodes need to be displaced in time. To displace them temporally, a backoff algorithm is used (example binary exponential backoff (BEB)). For example, in BEB algorithm, whenever a node's transmission is involved in a collision with another node's transmission, both nodes will choose a random waiting time and wait for this amoiunt of time before attempting again. If they are not successful in this attempt, they double their contention window and choose a randoim waiting time before transmitting again. This process will be repeated for certain number of attempts. If the nodes are not successful in their transmission after this limit, the packets will be dropped from their queue. Answered by C. Rama Krishna, NITTTR, Chandigarh, India on 03.12.2008 at 11.40 AM (IST)

What are the advantages and disadvantages of dijkstra-scholten algorithm versus Huangs algorithm?

Main disadvantages:

The major disadvantage of the algorithm is the fact that it does a blind search

there by consuming a lot of time waste of necessary resources.

Another disadvantage is that it cannot handle negative edges. This leads to

acyclic graphs and most often cannot obtain the right shortest path.

Can microwave transmission use terrestrial systems?

it is the transmission of microwaves. One person throws a microwave to another person and so on.

Write a program to find gcd using recursive method in java?

for two positive integers:

public static int gcd(int i1, int i2) {

// using Euclid's algorithm

int a=i1, b=i2, temp;

while (b!=0) {

temp=b;

b=a%temp;

a=temp;

}

return a;

}

What are the different tree methodologies in data structure?

The question itself is a bit vague since it doesn't suggest whether you're asking about the types of trees or the operations which can be performed on trees.

A tree is a data structure which stores information in a logical way that typically is ideally suited for searching quickly, often by ordering the nodes or items of the tree, also ideally, nodes should be able to be added to or removed from a tree quickly and efficiently. Often, trees are chosen as a means of simply structuring data in a meaningful way with no concerns as to their performance.

When trees are chosen as an alternative to a list, the reason for this is to gain the benefits of rapid insertion, searching and deletion of nodes. Common tree structures for this purpose are the binary tree and the black and red tree. A binary tree has an extremely simple and extremely fast method of searching for data, but it is highly dependent on nodes being added in an order which is somewhat random. If ordered data is added to a tree, the depth of the tree will be linear, thereby providing no benefits over a linked list in addition, removal of nodes can cause a binary tree to have to be rebuilt as all the nodes beneath the deleted node will have to be re-added to the tree, typically under different nodes, commonly causing linear branches of the tree and slowing down application performance.

R&B trees were designed to address many of the issues of a binary tree. By developing a data structure which intentionally keeps the depth of the tree shallow, high speed searching and node removal can be achieved, but at a cost to the insertion algorithm which is designed to "shake things up" a little. R&B trees are far beyond the scope of this answer.

General trees are used less as a means of providing ideal performance but instead are intended as a means of providing structure for data. General trees store information in a way which reflects the data format itself. An example of a general tree is the file system of a disk drive. The root directory contains zero or more children which each contain zero or more children which each contain zero or

more... you get the point. This structure is also used for things like the abstract syntax tree of a compiler. Source code is parsed into "tokens" which are the structured as nodes of a tree which are then "walked" when optimizing and producing binary code.

There are many more types of trees. Many of which ate covered by Donald Knuth in extensive, if not insane detail in "The Art of Computer Programming".

Among the operations you'd perform on the tree are insertion, deletion, searching, walking, reduction, simplification and more.

How can you declare global an local variables in flowcharts?

The simple answer is you don't. The primary purpose of a flowchart is to show the flow of execution through an algorithm, with all primary functions and decisions described in broad, abstract terms.

There is no need to distinguish between local and global variables because that is an implementation detail -- it's far too low-level a concept for algorithm design.

All variables utilised by an algorithm should essentially be declared up front at the start of the flowchart and should therefore be treated as being local to that particular flowchart. It doesn't matter where those variables came from, only that they be initialised accordingly. The decision to make a variable global comes much later, once the interactions between different flowcharts have been established. Even so, a global variable should only ever be considered when the variable represents a truly global concept. In the vast majority of cases, passing arguments into functions is often the better option. Especially when separate algorithms are intended to run concurrently because making a global variable thread-safe can seriously impact performance. But this is not a concern in algorithm design, they are only of importance to the implementers; the class designers.

How do you write a program that gives the GCD of three given numbers in C plus plus?

To find the GCD of three numbers, a, b and c, you need to find the GCD of a and b first, such that d = GCD(a, b). Then call GCD(d, c). Although you could simply call GCD(GCD(a, b), c), a more useful method is to use an array and iteratively call the GCD(a, b) function, such that a and b are the first two numbers in the first iteration, which becomes a in the next iteration, while b is the next number. The following program demonstarates this method.

Note that the GCD of two numbers can either be calculated recursively or iteratively. This program includes both options, depending on whether RECURSIVE is defined or not. In a working program you'd use one or the other, but the iterative approach is usually faster because it requires just one function call and no additional stack space.

The program will create 10 random arrays of integers of length 3 to 5 and process each in turn. Note that the more numbers in the array, the more likely the GCD will be 1.

#include<iostream>

#include<time.h>

#define RECURSIVE // comment out to use iterative method

#define ARRAY // comment out to use non-arrays

#ifdef RECURSIVE

// Returns the GCD of the two given integers (recursive method)

unsigned int gcd(unsigned int a, unsigned int b)

{

if(!a)

return(b);

if(!b)

return(a);

if(a==b)

return(a);

if(~a&1)

{

if(b&1)

return(gcd(a>>1,b));

else

return(gcd(a>>1,b>>1)<<1);

}

if(~b&1)

return(gcd(a,b>>1));

if(a>b)

return(gcd((a-b)>>1,b));

return(gcd((b-a)>>1,a));

}

#else

// Returns the GCD of the two given integers (iterative method)

unsigned int gcd(unsigned int a, unsigned int b)

{

if(!a)

return(b);

if(!b)

return(a);

int c;

for(c=0; ((a|b)&1)==0; ++c)

{

a>>=1;

b>>=1;

}

while((a&1)==0)

a>>=1;

do{

while((b&1)==0)

b>>=1;

if(a>b)

{

unsigned int t=a;

a=b;

b=t;

}

b-=a;

}while(b);

return(a<<c);

}

#endif RECURSIVE

// Returns the greatest common divisor in the given array

unsigned int gcd(const unsigned int n[], const unsigned int size)

{

if( size==0 )

return( 0 );

if( size==1 )

return( n[0] );

unsigned int hcf=gcd(n[0],n[1]);

for( unsigned int index=2; index<size; ++index )

hcf=gcd(hcf,n[index]);

return(hcf);

}

int main()

{

using std::cout;

using std::endl;

srand((unsigned) time(NULL));

for(unsigned int attempt=0; attempt<10; ++attempt)

{

unsigned int size=rand()%3+3;

unsigned int* num = new unsigned int[size];

unsigned int index=0;

while(index<size)

num[index++]=rand()%100;

unsigned int hcf=gcd(num,size);

cout<<"GCD(";

index=0;

cout<<num[index];

while(++index<size)

cout<<','<<num[index];

cout<<") = "<<hcf<<endl;

delete[]num;

}

cout<<endl;

}