Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: printing out square or cube

1. ## printing out square or cube

hi all,
how do u output out square or cube in C? what i mean is like this:

5(cube)+4(cube)+3(cube)+2(cube)+1(cube)
i know there is a ascii code or something like that for the cube or square but not sure what it is or how to use it. a helping hand here would be very much appreciated...thanks

• Just make a simple test to view all the ASCII characters and their codes, like this:

Code:
```#include <stdio.h>

int main()
{

int i;
for(i=0; i<500; i+=6)
{
printf("%d: %c\t%d: %c\t%d: %c\t%d: %c\t%d: %c\t%d: %c\n", i, i, i+1, i+1, i+2, i+2, i+3, i+3, i+4, i+4, i+5, i+5);
}

return 0;
}```

• I found an ASCII reference table here:
http://www.lookuptables.com/

Hope it helps.

• thanks cfc but i dun think there is the ascii code for cube.....so, it din really help but if u have any more info on this, pls do reply...thanks a million

• You mean like a superscript 3? Like ³?

• Say you wanted to square a number, you could use this code (which I'm coming up with right now):

Code:
```//Somewhere up top:
long Power(long,long);

// Say you want to put 5 to the 8th power:
long x = Power(5,8);

//Somewhere down below (or up top):
long Power(long x, long y)
{
long result = x;
for (long i = 1; i < y; i++)
result += result * x;
return result;
}```
Correct me if I'm wrong or there's an easier way, but I think that will do what

• Originally Posted by Dunna
Correct me if ... there's an easier way
double pow(double base, double exponent) in <math.h>

• pow() is very slow though. But is that even the problem here? I thought it was just a ASCII question?

• yes, MHTML got what i meant.....so how do u print the power of 3 like in the quotes??

You mean like a superscript 3? Like ³?

• Try a typecast to 252, like this:

Code:
`(char)252`
So using printf:

Code:
`printf("%c",252)`
Will output ³.

[edit:] 253 will output a superscript 2.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•