LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-03-2010, 02:07 AM   #1
immadisetty
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Rep: Reputation: 0
Need explanation how does the output comes?????


hi friends,
I didnt understood how output is coming...can any one explain???


#include<stdio.h>

main(x,y)
{
for(;100>x++; )
for( y=2; x%y; )
printf(++y/x+"\0%d\n",x);
}










Thanks in advance;
 
Old 03-03-2010, 02:11 AM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Hi there!

I don't understand what the question is. Can you try and rephrase that?

Tell us what language this is (looks like C ??) and what happens when you compile and run the program, and what do you EXPECT to happen when you run the program?

Also, when posting bits of code, please use CODE tags, so that the formatting (if any is present) will remain intact and make reading the code easier.

Code tags can be had by using [code] above and below the block of code. The closing tag has a slash, like: /code inside the [brackets]

Sasha
 
Old 03-03-2010, 03:34 AM   #3
immadisetty
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
this is code in C language ....

What i was asking is I am getting the output ... but i didnt get what the logic is in getting the output .....

Last edited by immadisetty; 03-03-2010 at 03:37 AM.
 
Old 03-03-2010, 03:36 AM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,638
Blog Entries: 29

Rep: Reputation: 901Reputation: 901Reputation: 901Reputation: 901Reputation: 901Reputation: 901Reputation: 901Reputation: 901
Quote:
Originally Posted by immadisetty
[code]

#include<stdio.h>

main(x,y)
{
for(;100>x++; )
for( y=2; x%y; )
printf(++y/x+"\0%d\n",x);
}

[:/code]
This need to be typed in 'Capital' i.e. CODE and there are no ':' involved anywhere.

Last edited by TheIndependentAquarius; 03-03-2010 at 03:37 AM.
 
Old 03-03-2010, 03:51 AM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,303

Rep: Reputation: 216Reputation: 216Reputation: 216
Quote:
Originally Posted by anishakaul View Post
This need to be typed in 'Capital' i.e. CODE
It does not matter.
Quote:
and there are no ':' involved anywhere.
That does.
 
1 members found this post helpful.
Old 03-03-2010, 03:53 AM   #6
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,638
Blog Entries: 29

Rep: Reputation: 901Reputation: 901Reputation: 901Reputation: 901Reputation: 901Reputation: 901Reputation: 901Reputation: 901
Oh, you are right !
 
Old 03-03-2010, 04:02 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Quote:
Originally Posted by immadisetty View Post
this is code in C language ....

What i was asking is I am getting the output ... but i didnt get what the logic is in getting the output .....
By default the output goes to stdout which is by default the terminal. More info about stdout, stderr and stdin here.
 
Old 03-03-2010, 04:11 AM   #8
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I would say that the program is fairly ugly (clever maybe but ugly). It is using some characteristics of ASCII to essentially hide the output. The \0 character indicates the end of a string, so essentially nothing is displayed however if a one is displayed before the NUL character then this is treated as the start of heading which is terminated by the \0 and so the rest of the text is displayed. ++y/x will only be one if y is greater than x and that will only occur if x is a prime number, because of the x%y condition will fail if y ever takes on the value that is a factor of x.

Last edited by graemef; 03-03-2010 at 04:13 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Explanation of iwconfig output? SlowCoder Linux - Networking 1 05-21-2009 05:19 AM
wlan diag output explanation shinystuffrox Linux - Wireless Networking 1 01-17-2008 07:08 PM
An explanation of my "route -n" output. uncle-c Linux - Newbie 4 12-02-2007 05:22 PM
Need explanation about all groups madking75 Slackware 4 11-26-2006 12:16 PM
I Could Use An Explanation winger Linux - General 3 04-13-2002 11:32 PM


All times are GMT -5. The time now is 09:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration