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

Program using putstr function in pointer in c?

#include <stdio.h>

int main (int argc, char **argv)

{

puts (argv[0]);

return 0;

}

C plus plus program using function median that take three parameters of type double and returns the median of the three?

There are several ways to implement this, however the basic principal is to sort the doubles in ascending order and return the middle element (in this case the 2nd element). The simplest implementation uses a 3-element array which is then sorted using an insertion sort, as shown in the following example.

#include<iostream>

#include<list>

double median(double& x, double& y, double& z)

{

// initialise the array

double a[3] = { x, y, z };

// sort the array

for(int i=1; i<3; ++i)

{

int hole=i;

int prev=hole-1;

double cur=a[hole];

while(hole && cur<a[prev])

{

a[hole]=a[prev];

--hole, --prev;

}

a[hole]=cur;

}

// return the middle element.

return( a[1] );

}

int main()

{

using namespace std;

double a, b, c;

a = 0.9;

b = 0.1;

c = 0.5;

cout<<"a="<<a<<endl;

cout<<"b="<<b<<endl;

cout<<"c="<<c<<endl;

cout<<"median="<<median(a,b,c)<<endl;

return(0);

}

Output:

a=0.9

b=0.1

c=0.5

median=0.5

It should be noted that when dealing with an even number of elements (such as 4 or 6), then there is no middle element, so you therefore need take the mean of the two middle elements instead. So if the sorted numbers are 0.1, 0.2, 0.5 and 0.9, then the median is the mean of 0.2 and 0.5, which is 0.35 (e.g., ( 0.2 + 0.5 ) / 2).

What is sequential programming?

In the early days of computing, programs were serial, that is, a program consisted of a sequence of instructions, where each instruction executed one after the other. It ran from start to finish on a single processor.

reference: http://code.google.com/edu/parallel/mapreduce-tutorial.html

List of graphics commands in C?

1. There are no commands in C.
2. Graphics can be used by system-dependent libraries so you have to specify the platform you are using (MS DOS, MS Windows, X Window, etc).

What is the advantage of switch over multiple IF Statement?

In my own personal opinion the switch statement is easier to understand and to add newer cases to without disturbing the logic.

In some compilers the switch statement may generate better machine code because the switch is actually wired into the hardware.

What program can be written to count the number of alphanumerics in a string?

public int getStringLength(String val) {

return val.length();

}

There is an inbuilt functionality in strings that counts the number of alphabets in a string called length()

What is parameter passing by value and by reference to a function?

Pass by value means the value of the actual argument is assigned to the formal argument of the function. This is how all functions work in all languages, but in some languages, such as Java, the implementation details may be hidden from us so it may not be obvious pass by value is occurring. When we say pass by reference what we really mean is that the value being passed is a memory address rather than an ordinary value. That is; the memory address is being passed by value. Memory addresses can only be stored in pointers, so for a function to accept an address its formal argument must be pointer of the same type. In languages that do not support pointers, such as Java, the pointers are still there we just don't have access to them.

In C++ we also have a native reference type. A reference is nothing more than an alias, an alternative name for an object of the same type. Unlike a pointer, a reference cannot change which object it refers to; it always refers to the same object it was assigned when it came into scope. Moreover, a reference can never be null. As a result, references are much easier to work with than pointers because we know that an object must exist if we have a reference. With pointers, we must test the pointer is non-null before we can determine if it refers to an actual object. In addition, a pointer has storage and identity whereas a reference does not. If we attempt to take the address of a reference, we take the address of the object being referred to. If we take the address of a pointer we get the pointer's own address (as opposed to the address stored at that address).

Although C++ supports a native reference type, behind the scenes the compiler uses pointers to implement them. So references are really just passed by value the same way pointers are passed by value. Regardless, if a function accepts either a pointer or a reference, it is said to be using the pass by reference semantic, otherwise it is using the (default) pass by value semantic.

What is the advantage of auto indexing?

If you are referring to the use of the auto-increment/decrement operator, it is expressed more simply, and in some hardware architectures it is a hard-wired machine instruction, resulting in a faster program.

Why to use String in c?

C doesn't have String data-type, so don't use it.

What is a relational operators in c?

Relational operators are those operators which shows relation between two operands. e.g. ==, <=,>=,<,>

Program on matrix multiplication?

#include<stdio.h>

void main()

{

int a[3][3],b[3][3],c[3][3],i,j,k;

clrscr();

printf("Enter elements of A:");

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

for(j=0;j<=2;j++)

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

printf("Enter elements of B:");

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

for(j=0;j<=2;j++)

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

printf("A:");

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

{

for(j=0;j<=2;j++)

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

printf("");

//To change line.

}

printf("B:");

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

{

for(j=0;j<=2;j++)

printf("%d ",b[i][j]);

printf("");

}

k=0;

while(k<=2)

{

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

{

int sum=0;

for(j=0;j<=2;j++)

sum=sum+a[i][j]*b[j][k];

c[i][k]=sum;

}

k++;

}

printf("Result: ");

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

{

for(j=0;j<=2;j++)

printf("%d ",c[i][j]);

printf("");

}

getch();

}

IN a circular doubly linked list with 10 nodes what is the minimum number of links that might have to be changed if we want to delete a node other than the head node?

Two, but there is no "might" about it. For any node (including the head) we must update exactly two links:

node.next.prev = node.prev

node.prev.next = node.next

If the node is also the head then we also update the head node pointer:

head = node.next

Aside from deleting the head node, the only special case we need to deal with is when the node being deleted is the only node in the list because this will refer to itself (thus head = node.next would result in head pointing to a node we're about to delete). However, we can avoid this special case by using a sentinel node to represent the head of the list. In this way, every list, including an empty list, always has at least one node; the sentinel.

Note that with a circular doubly linked list there no need to keep track of the tail node given that the head node's previous node already refers to the tail. However, with a singly-linked circular list we only need to keep track of the tail node since the next node after the tail is always the head node.

What can a pascal triangle be used?

pascal was designed as a simplier version for educational purpose, it was also designed to be a teaching tool for students of programming classes.