Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Ad icon
ZTE MF283U 4G Unlocked Router (Used)
ayanthamaxi
Updated:
Sunday at 8:26 PM
ලංකාවේ හොඳම උපකාරක පන්ති සහ ගුරුවරුන් එකම තැනකින් - TopTuition.lk
dulithapathum
Updated:
Saturday at 8:07 AM
Colombo
RidhMathraa ’26 🎶✨
Tmadhusanka
Updated:
Jul 15, 2026
Ad icon
Colombo
PXN V10 Pro Direct Drive Racing Wheel (Under Warranty)
Abdur Rahman
Updated:
Jul 15, 2026
Ad icon
USDT ණය සේවාව - USDT Loan Service
පුරවැසියා
Updated:
Jul 15, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
C/C++ Coding challenges
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="Enigma_1" data-source="post: 8017663" data-attributes="member: 78173"><p>[CODE]</p><p>#include <stdio.h></p><p>#include <stdlib.h></p><p></p><p>int number;</p><p>char* HexNumber =NULL;</p><p></p><p>int main()</p><p>{</p><p></p><p> printf("Please enter an integer :");</p><p> scanf("%d",&number);</p><p> HexNumber =(char*)malloc(50);</p><p> sprintf(HexNumber,"%x",number);</p><p> printf("1st method : hex representation is 0x%s\n",HexNumber);</p><p> printf("2nd method : hex representation is 0x%p\n",number);</p><p> printf("3rd method : hex representation is 0x%x\n",number);</p><p> system("pause");</p><p> return 0;</p><p>}</p><p>[/CODE][CODE]</p><p>#include <stdio.h></p><p>#include <stdlib.h></p><p>#include <string.h></p><p></p><p>unsigned int number,modval,Divval,index=0;</p><p>char* HexNumber =NULL;</p><p>char* tem;</p><p></p><p>int main()</p><p>{</p><p> printf("Please enter an integer :");</p><p> scanf("%d",&number);</p><p> HexNumber =(char*)malloc(50);</p><p> tem =(char*)malloc(3);</p><p> modval = number%16;</p><p> Divval = (int)number/16;</p><p> if(Divval<16)</p><p> {</p><p> sprintf(tem,"%d%d",Divval,modval);</p><p> strcpy(HexNumber,tem);</p><p> printf("Hex value is :%s\n",HexNumber);</p><p> system("pause");</p><p> exit(0);</p><p> }</p><p> else</p><p> {</p><p> sprintf(tem,"%d",modval);</p><p> strcpy(HexNumber,tem);</p><p> HexNumber = HexNumber+1;</p><p> index++;</p><p> }</p><p> while(Divval>16)</p><p> {</p><p> modval = Divval%16;</p><p> switch(modval)</p><p> {</p><p> case 10:</p><p> strcpy(HexNumber,"A");</p><p> break;</p><p> case 11:</p><p> strcpy(HexNumber,"B");</p><p> break;</p><p> case 12:</p><p> strcpy(HexNumber,"C");</p><p> break;</p><p> case 13:</p><p> strcpy(HexNumber,"D");</p><p> break;</p><p> case 14:</p><p> strcpy(HexNumber,"E");</p><p> break;</p><p> case 15:</p><p> strcpy(HexNumber,"F");</p><p> break;</p><p> default:</p><p> sprintf(tem,"%d",modval);</p><p> strcpy(HexNumber,tem);</p><p> break;</p><p> }</p><p> HexNumber = HexNumber+1;</p><p> Divval = (int)Divval/16;</p><p> index++;</p><p> }</p><p> sprintf(tem,"%d",Divval);</p><p> strcpy(HexNumber,tem);</p><p> printf("The Hex value is 0x");</p><p> while(strlen(HexNumber)!=(index+2))</p><p> {</p><p> printf("%c",HexNumber[0]);</p><p> HexNumber--;</p><p> }</p><p> printf("\n");</p><p> system("pause");</p><p> return 0;</p><p>}</p><p></p><p></p><p>[/CODE]here are my solutions.</p><p><img src="/styles/default/xenforo/smilies/default/D.gif" class="smilie" loading="lazy" alt=":D" title="Big grin :D" data-shortname=":D" /><img src="/styles/default/xenforo/smilies/default/D.gif" class="smilie" loading="lazy" alt=":D" title="Big grin :D" data-shortname=":D" /></p></blockquote><p></p>
[QUOTE="Enigma_1, post: 8017663, member: 78173"] [CODE] #include <stdio.h> #include <stdlib.h> int number; char* HexNumber =NULL; int main() { printf("Please enter an integer :"); scanf("%d",&number); HexNumber =(char*)malloc(50); sprintf(HexNumber,"%x",number); printf("1st method : hex representation is 0x%s\n",HexNumber); printf("2nd method : hex representation is 0x%p\n",number); printf("3rd method : hex representation is 0x%x\n",number); system("pause"); return 0; } [/CODE][CODE] #include <stdio.h> #include <stdlib.h> #include <string.h> unsigned int number,modval,Divval,index=0; char* HexNumber =NULL; char* tem; int main() { printf("Please enter an integer :"); scanf("%d",&number); HexNumber =(char*)malloc(50); tem =(char*)malloc(3); modval = number%16; Divval = (int)number/16; if(Divval<16) { sprintf(tem,"%d%d",Divval,modval); strcpy(HexNumber,tem); printf("Hex value is :%s\n",HexNumber); system("pause"); exit(0); } else { sprintf(tem,"%d",modval); strcpy(HexNumber,tem); HexNumber = HexNumber+1; index++; } while(Divval>16) { modval = Divval%16; switch(modval) { case 10: strcpy(HexNumber,"A"); break; case 11: strcpy(HexNumber,"B"); break; case 12: strcpy(HexNumber,"C"); break; case 13: strcpy(HexNumber,"D"); break; case 14: strcpy(HexNumber,"E"); break; case 15: strcpy(HexNumber,"F"); break; default: sprintf(tem,"%d",modval); strcpy(HexNumber,tem); break; } HexNumber = HexNumber+1; Divval = (int)Divval/16; index++; } sprintf(tem,"%d",Divval); strcpy(HexNumber,tem); printf("The Hex value is 0x"); while(strlen(HexNumber)!=(index+2)) { printf("%c",HexNumber[0]); HexNumber--; } printf("\n"); system("pause"); return 0; } [/CODE]here are my solutions. :D:D [/QUOTE]
Insert quotes…
Verification
Haya warak paha keeyada? (haya wadi kireema paha)
Post reply
Top
Bottom