print no

Reply

Join Date: Dec 2008
Posts: 5
Reputation: nrupparikh is an unknown quantity at this point 
Solved Threads: 0
nrupparikh nrupparikh is offline Offline
Newbie Poster

print no

 
-1
  #1
Dec 29th, 2008
print 1 to 10 numbers with array in c
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 148
Reputation: mn_kthompson is an unknown quantity at this point 
Solved Threads: 33
mn_kthompson mn_kthompson is offline Offline
Junior Poster

Re: print no

 
0
  #2
Dec 29th, 2008
See the answer from this thread
http://www.daniweb.com/forums/thread164796.html

Modify as appropriate.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,593
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 187
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: print no

 
0
  #3
Dec 31st, 2008
... and here is how you would do this with Python:
  1. arr = [12, 7, 9, 25, 87]
  2.  
  3. for item in arr:
  4. print(item)
Just to compare the syntax, here is the same thing in C:
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int arr[] = {12, 7, 9, 25, 87};
  6. int i;
  7.  
  8. for(i = 0; i < sizeof(arr)/sizeof(int); i++)
  9. {
  10. printf("%d\n", arr[i]);
  11. }
  12.  
  13. return 0;
  14. }
Last edited by Ene Uran; Dec 31st, 2008 at 9:47 am. Reason: see c
drink her pretty in burbank
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,344
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 194
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: print no

 
0
  #4
Jan 2nd, 2009
There is "no beauty" in even simple C code! Let's all thank the Python development team for giving us a readable syntax. Come to think of it, they all were very fluent in C since the core of Python is writtten in C.

I guess the true beauty of C is somewhat hidden, it can do low level stuff more readable than assembly language.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,893
Reputation: evstevemd is a jewel in the rough evstevemd is a jewel in the rough evstevemd is a jewel in the rough 
Solved Threads: 171
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Posting Virtuoso

Re: print no

 
0
  #5
Jan 3rd, 2009
Its true ! Thanks Python Dev team. I saw one example from Ene where there was no indentation, I whoop it was horrible!
Anyway it is more readable than assembly but wait a minute snee, Assembly is more readable than 10000100101111, I mean a turbulent of machine code language!
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
"Try to be expert in everything and you become expert in nothing" - Me
---------------------------------
Windows Vista Home Premium SP2| MINGW 4.4.0|PHP 5.3.1|Python 2.6.4|JDK 1.6
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,088
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 183
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: print no

 
0
  #6
Jan 3rd, 2009
Originally Posted by sneekula View Post
There is "no beauty" in even simple C code!
"Beauty is only in the eye of the beholder".
Those that know, find a well written piece of code in C very motivating and easy to work with.
The comparison of languages as it has been described here, only shows the lack of knowledge.

for(i = 0; i < sizeof(arr)/sizeof(int); i++) There's no need to evaluate sizeof(arr)/sizeof(int) every single time in the loop, since it never changes.
Last edited by Aia; Jan 3rd, 2009 at 2:54 pm.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan stating how a liberal's mind works.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,152
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 282
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Veteran Poster

Re: print no

 
0
  #7
Jan 3rd, 2009
I don't agree, because the compiler can see that sizeof(arr)/sizeof(int) never changes, so it certainly generates the code with a constant value. Isn't it a lack of knowledge Aia ? Knowledge, beauty, great philosophical problems to think about !
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,088
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 183
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: print no

 
0
  #8
Jan 3rd, 2009
Originally Posted by Gribouillis View Post
I don't agree, because the compiler can see that sizeof(arr)/sizeof(int) never changes, so it certainly generates the code with a constant value. Isn't it a lack of knowledge Aia ? Knowledge, beauty, great philosophical problems to think about !
The compiler doesn't miraculously change that expression into a constant. It evaluates each time through the loop. An unnecessary waste of CPU cycles when making a single call and keeping the value would have been sufficient.

[As a way of clarification]
The comment about sizeof() was not the reference to lack of knowledge, but the comparison of languages base on syntax, which is why I said, "The comparison of languages as it has been described here".
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan stating how a liberal's mind works.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,152
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 282
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Veteran Poster

Re: print no

 
0
  #9
Jan 3rd, 2009
I tried comparing the assembly code produced when you remplace sizeof(arr)/sizeof(int) by the constant 5. The diff between the 2 programs is
  1. < cmpl $4, -8(%ebp)
  2. < jle .L3
  3. ---
  4. > movl -8(%ebp), %eax
  5. > cmpl $4, %eax
  6. > jbe .L3
So the difference is only one movl instruction.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,088
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 183
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: print no

 
0
  #10
Jan 3rd, 2009
>So the difference is only one movl instruction.

cmpl $4, -8(%ebp) is not the same that cmpl $4, %eax

jle .L3 in not the same that jbe .L3

movl -8(%ebp), %eax is in a loop by virtue of "Jump if Below or Equal" Having the opportunity to execute many times. So it is not "only one mov1 instruction" executed only once.
Last edited by Aia; Jan 3rd, 2009 at 9:17 pm.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan stating how a liberal's mind works.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 646 | Replies: 9
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC