Click here to Skip to main content
15,936,460 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
How do I print the symbol theta in C language

What I have tried: idea..................
Updated 5-Mar-17 1:13am

#include <stdio.h>

int main()
    printf("Theta: Θ\n");

    return 0;
Share this answer
ArvindSai 4-Mar-17 9:54am    
I don't find any key on my keyboard that prints the symbol theta, besides I found myself that ASCII 233 will hold the symbol for theta, How did you enter it through keyboard.
Graeme_Grant 4-Mar-17 10:06am    
OriginalGriff 4-Mar-17 10:13am    
Depends - the simplest way is just to copy'n'paste the character. That's what I did!

Bear in mind that Windows doesn't use ASCII - it uses Unicode, which is a 16 bit "super version" of ASCII (which is technically 7 bit, but has an Enhanced version which is 8 bit and includes Theta). So you want the Unicode Theta which is \u03f4 and may (or may not) be enterable as a string character in your C - depending on what the compiler is.
See what I mean that copy'n'paste is easier? :laugh:
ArvindSai 4-Mar-17 10:11am    
Well thank you, but my laptop keyboard doesn't have the numpad, just the numbers keys above the alphabets i tried using that but it didn't work, how can I do it without using Numpad
ArvindSai 4-Mar-17 10:15am    
That should work:laugh:
Google gods have the answer that you are looking for...

Search used: theta character hex value[^]

Answer found: Unicode Character 'GREEK SMALL LETTER THETA' (U+03B8)[^]
Share this answer
[no name] 5-Mar-17 7:38am    
A 5 for such a complete answer.
I mean show how to Google _including_ the appropriate keywords and last but not least giving a hint which answer may help.
Graeme_Grant 5-Mar-17 7:52am    
:) They are gods ... so easy to find what you are looking for... even my 75+-year-old parents find it easy... and they have Logizomechanophobia[^] ;)
I am not able to print to the console but I am attaching a program which writes to a text file that can be opened in notepad (or notepad++)
The UTF-8 spec is detailed in wikipedia and the code is based on that. There is also a commented out code with the link.

#include <stdio.h>

#define MAX_PRINT 		25

int codepoint2utf8(unsigned char *utf8, unsigned int codepoint);
int getbytecount(unsigned int codepoint);

unsigned int alpha = 0x3b1; // UNICODE value for ALPHA
unsigned char utf8str[10];

unsigned char utf8_flag_bytes[] = {	0xef, 0xbb, 0xbf };  // these leading values at start of file (.txt) denote UTF-8 encoding

char *filename = "greek.txt";
void main()
	FILE *fp;
	int codelen;
	int i;
	fp = fopen(filename, "wb");
	fwrite(utf8_flag_bytes, 1, 3, fp);  // first write the UTF-8 signature to the start of file
	for(i = 0; i < MAX_PRINT; i++)
		codelen = codepoint2utf8(utf8str, alpha + i);
		codelen += codepoint2utf8(utf8str + codelen, ' ');

		fwrite(utf8str, 1, codelen, fp);

int codepoint2utf8(unsigned char *utf8, unsigned int codepoint)
	unsigned char byteval, mask, leadbyte = 0, countbit = 0;
	int numbytes, i;
	mask = 0x3f;   // mask for continuation byes ie for extracting least significant 6 bits
	numbytes = getbytecount(codepoint);
	if(numbytes > 1)
		countbit = (1 << 7);
	for(i = numbytes - 1; i > 0; i--, countbit >>= 1)
		byteval = (codepoint & mask) | (1 << 7);
		leadbyte |= countbit;  // set next significant bit for each byte added
		codepoint >>= 6;      // next 6 bits
		utf8[i] = byteval;
	leadbyte |= (countbit | codepoint);
	utf8[i] = leadbyte;
	return numbytes;

int getbytecount(unsigned int codepoint)
	unsigned int i, bits, continuations = 0, leadbits = 5;
	for(i = 31, bits = 0; i > 0 && bits == 0; i--)
		if((1 << i) & codepoint)
			bits = i + 1;
	if(bits <= 7)
		goto exitpoint;
	continuations = 1;  // min value
	while(bits > leadbits + continuations * 6)  // 'leadbits' is no of bits avail for coding in lead byte 
	{                                           // every continuation byte is of the form 10xxxxxx where 'xxxxxx' represents part codepoint value
	return (1 + continuations);  // no of bytes reqd is 1(for lead byte) + no of continuation bytes

-- link
if (c<0x80) *b++=c;
else if (c<0x800) *b++=192+c/64, *b++=128+c%64;
else if (c-0xd800u<0x800) goto error;
else if (c<0x10000) *b++=224+c/4096, *b++=128+c/64%64, *b++=128+c%64;
else if (c<0x110000) *b++=240+c/262144, *b++=128+c/4096%64, *b++=128+c/64%64, *b++=128+c%64;
else goto error;
Share this answer
[no name] 5-Mar-17 7:15am    
Looks like he is not OP ;)
Graeme_Grant 5-Mar-17 7:31am    
whoopsie... sounded like him... must check in future...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900