subscript and superscript

This is a discussion on subscript and superscript within the C Programming forums, part of the General Programming Boards category; How do i display subscript and superscript on the screen ? Can I do it using printf ? for example ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    2

    subscript and superscript

    How do i display subscript and superscript on the screen ?
    Can I do it using printf ?

    for example superscript 2 as in x^2.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Ehh... this is hard. Can't be done with ANSI C. The symbol for a superscript 2 is a special case however, there is an ASCII character for that, so you could do x^2, but nothing else. At least, not using printf. Here is the code for a program that displays a table of the ASCII characters and their corresponding values...
    Code:
    #include <stdio.h>
    
    int main ()
    {
     int c, i;
    
     // There are 256 ascii characters, from 0 to 255.
     // A lot of the values just can't be displayed.  For example, there is
     //  the newline character, a backspace character, a tab character, and
     //  probably the most entertaining one, the beep character.
     
     for (c = 0; c < 256; )
     {
     // Adjust the stopping value for i accordingly.
      for (i = 0; i < (80) / 7 && c < 256; i++, c++)
      {
       printf ("%3d %c  ", c, c);
      }
      // Depending on stopping value, this may or may not be commented out.
      printf ("\n");
     }
     return 0;
    }
    If you really need to do this, you're gonna need some graphics routines, which would mean allegro. I reccomend just using the ^ symbol to represent powers.
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    2
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Subscript and Superscript
    By GaPe in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 03-06-2002, 02:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21