# Thread: Help with few programs..

1. ## Help with few programs..

I came across an interview process and i couldn able to answer few of their questions. But i want to enlighten myself with the answers of the questions.. plz help me with the answers to those questions. .. . .

1 . Program to truncate a given floating point value (e.g.16.25=16). You should not assign the float value to integer & then copy the int value to float….

2 . Program to find the position of decimal point in a given floating point value.

3. Program to swap two numbers without using assignment operator in any part of the program.

i answered others questions ... but found it confusing

2. In order to answer the first two questions you need to know how float is represented internally. Here's a handy link:
Clusty Search Â» ieee floating point

>3. Program to swap two numbers without using assignment operator in any part of the program.
It could be done using XOR.

EDIT: Oh, I thought "without temp variable" lol.

3. i found out the answer for the 3rd question..
u could use inline asm code ...

like asm mov ax,a
this will solve that assingment operator problem..

4. I'm sure it won't.

5. Originally Posted by Brafil
I'm sure it won't.
got any idea other than that ?? ? ? ??!?!

6. >3. Program to swap two numbers without using assignment operator in any part of the program.
Okay, the only thing that came into my mind is to read values from file/stdin, then make a temporary file, write them there, and read backwards. Looks dumb, but as for me, the very question looks pretty dumb either.

7. #include < stdio.h >
#include < conio.h >
void main()
{
int a,b;
clrscr();
printf("\nEnter variables to swap-->");
scanf("%d %d",&a,&b);
printf("\nBefore swapping:- %d %d",a,b);
asm mov AX,a;
asm mov BX,b;
asm mov b,AX;
asm mov a,BX;
printf("\nAfter swapping :- %d %d",a,b);
getch();
}

8. GL.Sam had already posted the solution - simply XOR the two numbers, but beware, if they are the same, they will both be 0. I think this is what your instructors want - just google "xor swap".

9. Originally Posted by Brafil
GL.Sam had already posted the solution - simply XOR the two numbers, but beware, if they are the same, they will both be 0. I think this is what your instructors want - just google "xor swap".
XOR will still require an assignment statement " = " .

10. No. You can use "^=", which is a compound operator.

11. Originally Posted by Brafil
No. You can use "^=", which is a compound operator.
I'd consider that an assignment operator...

12. I've found it
Code:
```#include <stdio.h>
#include <string.h>

int main(void)
{
int a, b, temp;

scanf("%d %d", &a, &b);

memcpy(&temp, &a, sizeof(int));
memcpy(&a, &b, sizeof(int));
memcpy(&b, &temp, sizeof(int));

printf("%d %d\n", a, b);

return 0;
}```

13. It kinda takes away from the whole "homework" aspect if you just show up and someone else does everything for you.

Quzah.

14. Originally Posted by quzah
It kinda takes away from the whole "homework" aspect if you just show up and someone else does everything for you.

Quzah.
dude.. i said it was asked on my interviews. It was not an homework btw and am not a kid going to school. I just messed up that interview coz these kinds of logical questions.. i want to make myself clear thats why posted here.. :|

15. Maybe you should go to school. I mean, you're interviewing for some sort of programming job, but you don't know how to program.

Quzah.