Sunday, July 26, 2009

I need help coding programs in the C programming language?

What code could be used in the C programming language to print the following on the screen?





1) truncate and round 6.6





2) the ascii vale of the character “A”





3) the character that has the ascii value of 67








The output from the code should be as follows:





6.000000 7.000000


65


C

I need help coding programs in the C programming language?
If this is for a course you better get it together quick. You can see how easy this is.





#include "stdio.h"


#include "math.h"





int main ()


{


float x = 6.6;


char c = 'A';





printf("%f\n", round(x));


printf("%f\n", trunc(x));





printf("%d\n", c);


printf("%c\n", 67);


}
Reply:These are examples of basics of Type Casting...





For example, you want to know the ascii value of 'A'.. Then do this:





printf("%d", (int)'A');





or...





int ascii;





ascii = (int)'A';





'A' is a character, but it has an ascii value.. To show its ascii value, then you need to Type Cast it to integer. To Type Cast, as shown above, you just place an '(int)' before the character. Or if you want to type cast an int to a char, then just do this:





char ch;





ch = (char)67;





(^^,) http://ronaldborla.blogsome.com/
Reply:http://www.cplusplus.com/reference/clibr...


No comments:

Post a Comment