| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | [C] C Puzzles |
Hi Bruce! :-)
[...]
BDW> 3. Find if the given number is a power of 2.
int ispoweroftwo(unsigned int i)
{
int count = 0;
while (i) {
count += i & 1;
i = i >> 1;
}
return (count == 1);
}
BDW> 4. Multiply x by 7 without using multiplication (*) operator.
x = (x << 3) - x;
or
x = (x << 2) + (x << 1) + x;
BDW> 5. Write a function in different ways that will return f(7) = 4 and
BDW> f(4) = 7
int f1(int x)
{
if (x==4)
return 7;
else if (x==7)
return 4;
else
return x;
}
int f2(int x)
{
if (x < 5)
return x+3;
else
return x-3;
}
BDW> 6. Remove duplicates in array
We had that problem here lately. ;)
BDW> 7. Finding if there is any loop inside linked list.
For each entry, loop through all entries starting from the list head,
looking for identical element to next pointer in current element.
BDW> 8. Write code to determine if a TYPE is signed or unsigned. Got it?
Beats me.
BDW> OK, write code to determine if a value is unsigned or signed.
Huh? Whether a value is to be regarded as unsigned or signed depends solely
on the type used to interpret it. You can find out whether a signed value
is negative by looking at the leftmost bit, but that's it.
Ciao
Pascal
--- Msged/LNX 6.1.1
* Origin: sed s/$(echo $HOME | sed 's/[[:punct:]]/\\&/g')/~/ (1:153/401.2)SEEN-BY: 633/267 270 @PATH: 153/401 307 140/1 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.