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
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 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
Hath warak paha keeyada? (hatha wadikireema paha)
Post reply
Top
Bottom