Tuesday, July 28, 2009

C++ program to convert number to ascii number?

C++ program to convert number to ascii number?


i have been given an assignment to take a number input from user and convert it into its equivalent hexadecimal, octal and ascii values. i have done the hex and oct but i am sttruck on ascii can anyone plz help me....


(I NEED THE PROGRAM -%26gt; to convert user input number to ascii)


for example if the user inputs 65 the output should be A

C++ program to convert number to ascii number?
Forget the above, it's C, not C++! Use the following:





#include %26lt;iostream%26gt;





void main(void) {


int i;


std::cin %26gt;%26gt; i;


std::cout %26lt;%26lt; char(i);


}
Reply:#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;





void main()


{


int num;


clrscr();





printf("Enter the number: ");


scanf("%d",%26amp;num);





printf("The ascii equivalent is: %c",num);


getch();


}
Reply:Use the C-Standard function sprintf for those purposes:





int number = 1243;


char str[1024];


sprintf(str, "%i", number);





That should do it.


No comments:

Post a Comment