26.6.08

Swapping two integers without temporary variable.

We can do this thing in many ways, here are some.


int main()
{
int x, y;
printf("Enter x and y values \n");
scanf("%d %d", &x, &y);
printf("X=%d\t Y=%d\n", x, y);
printf("AFTER SWAP \n");

/* Swap using addition and subtraction */
x = x+y;/*Limitation is there addition should */
y = x-y;/* not over flow */
x = x-y;
printf("X=%d\t Y=%d\n", x, y);

/* Swap using multiplication and division */
x = x*y;/* Limitation is, Y should not be zero and*/
y = x/y;/* and x*y should not overflow */
x = x/y;
printf("X=%d\t Y=%d\n", x, y);

/* swap using exclusive OR */
x = x^y;
y = x^y;
x = x^y;
printf("X=%d\t Y=%d\n", x, y);

return 0;
}
Give the one line code to tell the given number is power of '2' or not.

The "C" code snippet is here:
  int main()
{
int num;

printf("Enter a number other than Zero \n");
scanf("%d", &num);

num&(num-1)?printf("Not a Power of 2 \n"):printf("Power of 2 \n");

return 0;
}


ld.so.1: fatal: .so: open failed: No such file or directory



This problem comes when the required ( liked *.so) libraries were not exist in the proper location in the system or the libraries not exist in system at all.

Remedy:

To know exactly which libraries are missing:

execute this command.

ldd "binaryname"

This command lists all the *.so that binary contains and there location in the system.

If any of the binary is missing it says .

From this report just copy the missing *.so into /usr/lib/ ( by default) or specified lib directory.