473,890 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing "hello , wolrd" with out using semicolon

Hi,
Can any body tell me how to print "hello,worl d" with out using semicolon

Thanks in advance ..
Bye
Prashanth Badabagni
Nov 14 '05
42 9914
Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> scribbled the following:
On Mon, 10 May 2004, Yakov Lerner wrote:
b_*********@hot mail.com (Prashanth Badabagni) wrote:
> Can anybody tell me how to print "hello,worl d" without using semicolon Here is a variation: write C program to print ";"
without using semicolon, digits, double quote, and single quote.
Assume ascii.

ASCII is off-topic in comp.lang.c. I think you meant to say,
"Do not assume ASCII." #include <stdio.h>
#include <stdlib.h>
#define Z ((int)NULL)
#define P(x) printf(#x
#define L(x) #x
#define S L(| |)[!Z]
int f(int l,int i){if((i=l,!Z)& &l==Z&&P(%c%c%d \n),S,S,Z)&&f
(++i,i)){}else if(--l==Z&&P(\n))&&f (++i,i)){}else if(--l==Z
&&P(%c%c%d\n),S ,S,Z)&&f(++i,i) ){}else if(--l==Z&&P(%c/\n),S
)&&f(++i,i)){}e lse if(exit(Z),Z){} }int main(){if(f(Z,Z )){}}


No fair with preprocessor trickery! When preprocessed, that code will
contain plenty of double quotes. If I'm allowed to assume ASCII, I can
write a program to do it containing double quotes only in standard
headers, even after preprocessing.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Immanuel Kant but Genghis Khan."
- The Official Graffitist's Handbook
Nov 14 '05 #21
Joona I Palaste <pa*****@cc.hel sinki.fi> writes:
Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> scribbled the following:
On Mon, 10 May 2004, Yakov Lerner wrote:
b_*********@hot mail.com (Prashanth Badabagni) wrote:
> Can anybody tell me how to print "hello,worl d" without using semicolon
Here is a variation: write C program to print ";"
without using semicolon, digits, double quote, and single quote.
Assume ascii.

ASCII is off-topic in comp.lang.c. I think you meant to say,
"Do not assume ASCII."

#include <stdio.h>
#include <stdlib.h>
#define Z ((int)NULL)
#define P(x) printf(#x
#define L(x) #x
#define S L(| |)[!Z]
int f(int l,int i){if((i=l,!Z)& &l==Z&&P(%c%c%d \n),S,S,Z)&&f
(++i,i)){}else if(--l==Z&&P(\n))&&f (++i,i)){}else if(--l==Z
&&P(%c%c%d\n),S ,S,Z)&&f(++i,i) ){}else if(--l==Z&&P(%c/\n),S
)&&f(++i,i)){}e lse if(exit(Z),Z){} }int main(){if(f(Z,Z )){}}


No fair with preprocessor trickery! When preprocessed, that code will
contain plenty of double quotes. If I'm allowed to assume ASCII, I can
write a program to do it containing double quotes only in standard
headers, even after preprocessing.


If I can assume ASCII, it's easy to do without using any preprocessor
facilities at all:

int main(void) { if (putchar((((mai n==main)+(main= =main))*((main= =
main)+(main==ma in)) * ((main==main)+( main==main)) * ((main==main)+
(main==main))* ((main==main)+( main==main)) * ((main==main)+( main==
main)))-(((main==main)+ (main==main))*( (main==main)+(m ain==main)))-
(main==main)), putchar((((main ==main)+(main== main))*((main== main)+
(main==main)) * ((main==main)+( main==main)))+( (main==main)+(m ain==
main))),exit(ma in!=main),main= =main){}}

Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #22
Martin Dickopp <ex************ ****@zero-based.org> scribbled the following:
Joona I Palaste <pa*****@cc.hel sinki.fi> writes:
Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> scribbled the following:
On Mon, 10 May 2004, Yakov Lerner wrote:
b_*********@hot mail.com (Prashanth Badabagni) wrote:
> Can anybody tell me how to print "hello,worl d" without using semicolon
Here is a variation: write C program to print ";"
without using semicolon, digits, double quote, and single quote.
Assume ascii.
ASCII is off-topic in comp.lang.c. I think you meant to say,
"Do not assume ASCII."

#include <stdio.h>
#include <stdlib.h>
#define Z ((int)NULL)
#define P(x) printf(#x
#define L(x) #x
#define S L(| |)[!Z]
int f(int l,int i){if((i=l,!Z)& &l==Z&&P(%c%c%d \n),S,S,Z)&&f
(++i,i)){}else if(--l==Z&&P(\n))&&f (++i,i)){}else if(--l==Z
&&P(%c%c%d\n),S ,S,Z)&&f(++i,i) ){}else if(--l==Z&&P(%c/\n),S
)&&f(++i,i)){}e lse if(exit(Z),Z){} }int main(){if(f(Z,Z )){}}


No fair with preprocessor trickery! When preprocessed, that code will
contain plenty of double quotes. If I'm allowed to assume ASCII, I can
write a program to do it containing double quotes only in standard
headers, even after preprocessing.

If I can assume ASCII, it's easy to do without using any preprocessor
facilities at all: int main(void) { if (putchar((((mai n==main)+(main= =main))*((main= =
main)+(main==ma in)) * ((main==main)+( main==main)) * ((main==main)+
(main==main))* ((main==main)+( main==main)) * ((main==main)+( main==
main)))-(((main==main)+ (main==main))*( (main==main)+(m ain==main)))-
(main==main)), putchar((((main ==main)+(main== main))*((main== main)+
(main==main)) * ((main==main)+( main==main)))+( (main==main)+(m ain==
main))),exit(ma in!=main),main= =main){}}


That's pretty clever. My original program to print "Hello, world"
without using literal values was pretty much the same way, except it
used a static variable and its negation to form 0 and 1, and then use
those to form all other natural numbers. I dare you to write a "Hello,
world" program in the way you are doing above. It won't require
particularly ingenious thinking but it will be tedious to type out.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"B-but Angus! You're a dragon!"
- Mickey Mouse
Nov 14 '05 #23
Martin Dickopp wrote:
int main(void) { if (putchar((((mai n==main)+(main= =main))*((main= =
main)+(main==ma in)) * ((main==main)+( main==main)) * ((main==main)+
(main==main))* ((main==main)+( main==main)) * ((main==main)+( main==
main)))-(((main==main)+ (main==main))*( (main==main)+(m ain==main)))-
(main==main)), putchar((((main ==main)+(main== main))*((main== main)+
(main==main)) * ((main==main)+( main==main)))+( (main==main)+(m ain==
main))),exit(ma in!=main),main= =main){}}


That's undefined behaviour: exit() is implicitly declared by the call
as a function returning int, but the standard function exit() is
defined as returning void.

Jeremy.
Nov 14 '05 #24
Joona I Palaste <pa*****@cc.hel sinki.fi> writes:
Martin Dickopp <ex************ ****@zero-based.org> scribbled the following:
Joona I Palaste <pa*****@cc.hel sinki.fi> writes:
Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> scribbled the following:
On Mon, 10 May 2004, Yakov Lerner wrote:
> b_*********@hot mail.com (Prashanth Badabagni) wrote:
> > Can anybody tell me how to print "hello,worl d" without using semicolon
> Here is a variation: write C program to print ";"
> without using semicolon, digits, double quote, and single quote.
> Assume ascii.

ASCII is off-topic in comp.lang.c. I think you meant to say,
"Do not assume ASCII."

#include <stdio.h>
#include <stdlib.h>
#define Z ((int)NULL)
#define P(x) printf(#x
#define L(x) #x
#define S L(| |)[!Z]
int f(int l,int i){if((i=l,!Z)& &l==Z&&P(%c%c%d \n),S,S,Z)&&f
(++i,i)){}else if(--l==Z&&P(\n))&&f (++i,i)){}else if(--l==Z
&&P(%c%c%d\n),S ,S,Z)&&f(++i,i) ){}else if(--l==Z&&P(%c/\n),S
)&&f(++i,i)){}e lse if(exit(Z),Z){} }int main(){if(f(Z,Z )){}}

No fair with preprocessor trickery! When preprocessed, that code will
contain plenty of double quotes. If I'm allowed to assume ASCII, I can
write a program to do it containing double quotes only in standard
headers, even after preprocessing.

If I can assume ASCII, it's easy to do without using any preprocessor
facilities at all:

int main(void) { if (putchar((((mai n==main)+(main= =main))*((main= =
main)+(main==ma in)) * ((main==main)+( main==main)) * ((main==main)+
(main==main))* ((main==main)+( main==main)) * ((main==main)+( main==
main)))-(((main==main)+ (main==main))*( (main==main)+(m ain==main)))-
(main==main)), putchar((((main ==main)+(main== main))*((main== main)+
(main==main)) * ((main==main)+( main==main)))+( (main==main)+(m ain==
main))),exit(ma in!=main),main= =main){}}


That's pretty clever. My original program to print "Hello, world"
without using literal values was pretty much the same way, except it
used a static variable and its negation to form 0 and 1, and then use
those to form all other natural numbers. I dare you to write a "Hello,
world" program in the way you are doing above. It won't require
particularly ingenious thinking but it will be tedious to type out.


I tend to use computers for boring and tedious tasks. :-) Below is a
program which reads some text from standard input (until end-of-file
condition or an error is encountered) and writes to standard output a
C program in the spirit of the above (but without nice formatting).
#include <stdio.h>

int main (void)
{
int ch;
puts ("int main(void){if(" );
while ((ch = getchar ()) != EOF)
{
puts ("putchar(") ;
if (ch == 0)
puts ("main!=main ");
else
{
int parens = 0;
while (1)
{
if (ch & 1)
puts ("(main==main)" );
if ((ch >>= 1) != 0)
{
puts ("+((main==main )+(main==main)) *(");
++parens;
}
else
break;
}
while (parens-- > 0)
putchar (')');
}
puts ("),");
}
puts ("exit(main!=ma in),main==main) {}}");
return 0;
}
Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #25
Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> writes:
Martin Dickopp wrote:
int main(void) { if (putchar((((mai n==main)+(main= =main))*((main= =
main)+(main==ma in)) * ((main==main)+( main==main)) * ((main==main)+
(main==main))* ((main==main)+( main==main)) * ((main==main)+( main==
main)))-(((main==main)+ (main==main))*( (main==main)+(m ain==main)))-
(main==main)), putchar((((main ==main)+(main== main))*((main== main)+
(main==main)) * ((main==main)+( main==main)))+( (main==main)+(m ain==
main))),exit(ma in!=main),main= =main){}}


That's undefined behaviour: exit() is implicitly declared by the call
as a function returning int, but the standard function exit() is
defined as returning void.


Good catch. The only solution I can think of is to rely on the
"implicitly return 0 from main" behavior in C99.

Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #26

On Mon, 10 May 2004, Joona I Palaste wrote:

Martin Dickopp <ex************ ****@zero-based.org> scribbled the following:
If I can assume ASCII, it's easy to do without using any preprocessor
facilities at all:


That's pretty clever. My original program to print "Hello, world"
without using literal values was pretty much the same way, except it
used a static variable and its negation to form 0 and 1, and then use
those to form all other natural numbers. I dare you to write a "Hello,
world" program in the way you are doing above. It won't require
particularly ingenious thinking but it will be tedious to type out.


Let's hear it for program generators! (Yes, this was tweaked by
hand to get it nice and square. But the factoring of each ASCII value
and printing of all the 'main==main's was done by computer.)

-Arthur

int main(void){if(p utchar(((((main ==main)+(main== main))*((main== main)+
(main==main)+(m ain==main)+(mai n==main)))*(((m ain==main)+(mai n==main)+(
main==main))*(( main==main)+(ma in==main)+(main ==main)))))&&pu tchar(((((
(main==main)+(m ain==main))*((m ain==main)+(mai n==main)+(main= =main)))*(
(((main==main)+ (main==main)+(m ain==main))*((( main==main)+(ma in==main))
*((main==main)+ (main==main)+(m ain==main))))-(main==main)))-(main==main
)))&&putchar((( ((main==main)+( main==main)+(ma in==main))*((ma in==main)+
(main==main)+(m ain==main)))*(( (main==main)+(m ain==main)+(mai n==main))*
((main==main)+( main==main)+(ma in==main)+(main ==main)))))&&pu tchar(((((
main==main)+(ma in==main)+(main ==main))*((main ==main)+(main== main)+!!!(
main!=main)))*( ((main==main)+( main==main)+(ma in==main))*((ma in==main)+
(main==main)+(m ain==main)+(mai n==main)))))&&p utchar((((main= =main)+!!!
(main!=main)+(m ain==main))*((( (main==main)+(m ain==main))*((( !!!(main!=
main)+(main==ma in)+(main==main )+(main==main)) *((main==main)+ !!!(main!=
main)+(main==ma in)+(main==main )+(main==main)) )-(main==main)))-!(main!=
main))))&&putch ar((((main==mai n)+(main==main) +(main==main)+( main==main
))*((((main==ma in)+(main==main )+(main==main)) *((main==main)+ !!!(main!=
main)+(main==ma in)+(main==main )))-(main==main)))) &&putchar(((!!( main==
main)+(main==ma in)+(main==main )+(main==main)) *(((main==main) +!!(main==
main))*((main== main)+(main==ma in)+(main==main )+!!!!!(main!=m ain)))))&&
putchar((((((ma in==main)+(main ==main))*((main ==main)+(main== main)+!!!!
(main==main)+(m ain==main)))-(main==main))*( (((main==main)+ (main==main)
+(main==main))* (((main==main)+ (main==main))*( (main==main)+(m ain==main)
+(main==main))) )-(main==main)))) &&putchar((((ma in==main)+(main ==main)+
(main==main))*( (((main==main)+ (main==main))*( (((main==main)+ !!!(main!=
main)+(main==ma in)+(main==main ))*((main==main )+(main==main)+ !!!(main!=
main)+(main==ma in)+(main==main )))-(main==main)))-(main==main)))) &&!!!!
putchar(((((mai n==main)+(main= =main))*((main= =main)+(main==m ain)+(main
==main)))*((((m ain==main)+(mai n==main)+(main= =main)+(main==m ain))*(!!(
main==main)+(ma in==main)+(main ==main)+(main== main)+(main==ma in)))-!!!(
main!=main))))& &putchar(((((ma in==main)+(main ==main)+(main== main))*(!!
(main==main)+(m ain==main)+(mai n==main)))*(((m ain==main)+(mai n==main)+(
main==main))*(( main==main)+(ma in==main)+(main ==main)+!(main! =main)))))
&&putchar(((((m ain==main)+(mai n==main))*((mai n==main)+(main= =main)+!!(
main==main)+(ma in==main)+(main ==main)))*(((ma in==main)+(main ==main))*(
(main==main)+(m ain==main)+(mai n==main)+(main= =main)+(main==m ain)))))&&
putchar((((main ==main)+(main== main)+(main==ma in))*((((main== main)+!!!(
main!=main)+(ma in==main))*((ma in==main)+(main ==main)+(main== main)+!!!(
main!=main)))-(main==main)))) &&putchar((((ma in==main)+(main ==main))*((
main==main)+(ma in==main)+(main ==main)+(main== main)+(main==ma in))))){}}
Nov 14 '05 #27
Martin Dickopp wrote:
Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> writes:
Martin Dickopp wrote:
int main(void) { if (putchar((((mai n==main)+(main= =main))*((main= =
main)+(main==ma in)) * ((main==main)+( main==main)) * ((main==main)+
(main==main))* ((main==main)+( main==main)) * ((main==main)+( main==
main)))-(((main==main)+ (main==main))*( (main==main)+(m ain==main)))-
(main==main)), putchar((((main ==main)+(main== main))*((main== main)+
(main==main)) * ((main==main)+( main==main)))+( (main==main)+(m ain==
main))),exit(ma in!=main),main= =main){}}


That's undefined behaviour: exit() is implicitly declared by the call
as a function returning int, but the standard function exit() is
defined as returning void.


Good catch. The only solution I can think of is to rely on the
"implicitly return 0 from main" behavior in C99.


If you use C99, though, you lose implicit declarations altogether, so
you need a declaration for putchar(), with a semicolon.

Jeremy.
Nov 14 '05 #28
Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> writes:
Martin Dickopp wrote:
Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> writes:
Martin Dickopp wrote:
int main(void) { if (putchar((((mai n==main)+(main= =main))*((main= =
main)+(main==ma in)) * ((main==main)+( main==main)) * ((main==main)+
(main==main))* ((main==main)+( main==main)) * ((main==main)+( main==
main)))-(((main==main)+ (main==main))*( (main==main)+(m ain==main)))-
(main==main)), putchar((((main ==main)+(main== main))*((main== main)+
(main==main)) * ((main==main)+( main==main)))+( (main==main)+(m ain==
main))),exit(ma in!=main),main= =main){}}

That's undefined behaviour: exit() is implicitly declared by the call
as a function returning int, but the standard function exit() is
defined as returning void.


Good catch. The only solution I can think of is to rely on the
"implicitly return 0 from main" behavior in C99.


If you use C99, though, you lose implicit declarations altogether, so
you need a declaration for putchar(), with a semicolon.


Okay, I give up. :) There's no solution.

Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #29
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote in message news:<Pi******* *************** ************@un ix40.andrew.cmu .edu>...
On Mon, 10 May 2004, Yakov Lerner wrote:

b_*********@hot mail.com (Prashanth Badabagni) wrote:
Can anybody tell me how to print "hello,worl d" without using semicolon
Here is a variation: write C program to print ";"
without using semicolon, digits, double quote, and single quote.
Assume ascii.


ASCII is off-topic in comp.lang.c. I think you meant to say,
"Do not assume ASCII."

#include <stdio.h>
#include <stdlib.h>
#define Z ((int)NULL)
#define P(x) printf(#x
#define L(x) #x
#define S L(| |)[!Z]
int f(int l,int i){if((i=l,!Z)& &l==Z&&P(%c%c%d \n),S,S,Z)&&f
(++i,i)){}else if(--l==Z&&P(\n))&&f (++i,i)){}else if(--l==Z


The \ in \n is not at the end of a line, not part of a character or
string literal, not part of a universal character, not part of an
include header, and does not constitute a punctuator or other
preprocessor token.

I know gcc does not issue a diagnostic, but unless I'm missing
something, it's a syntax error.
&&P(%c%c%d\n),S ,S,Z)&&f(++i,i) ){}else if(--l==Z&&P(%c/\n),S
)&&f(++i,i)){}e lse if(exit(Z),Z){} }int main(){if(f(Z,Z )){}}


--
Peter
Nov 14 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
5595
by: ankursinha | last post by:
Hi, Is it possible to write a C program that prints "Hello World" on screen without having a single semi-colon in the entire program? The extra constraint here is that u r not allowed to use if,while,switch etc. So far,i figured this could be done by insertint the printf statement in main as shown: int main(int argc=printf("Hello world")
51
4198
by: Spidey | last post by:
for(;0;) printf("hello"); even the condition s wrong i get a hello printed on the screen y s this happening
0
9979
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11234
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7171
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6058
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4682
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.