445,654 Members | 936 Online
Need help? Post your question and get tips & solutions from a community of 445,654 IT Pros & Developers. It's quick & easy.

# how to get

 P: n/a i am not getting the numerical figure . 1 12 123 1234 12345 plse help me. i am writing these following logic: # include void main() { int i,j; for(i=0;i<=5;i++) { for(j=1;j
5 Replies

 P: n/a Advait Vaidya wrote: i am not getting the numerical figure . 1 12 123 1234 12345 plse help me. i am writing these following logic: # include void main() { int i,j; for(i=0;i<=5;i++) { for(j=1;j int main(int argc, char * argv[]) { for(int i(0); i < 6; i++) { for(int j(1); j < i + 1; j++) std::cout << j; std::cout << std::endl; } } Oct 2 '06 #2

 P: n/a "imperfectfreak" i am not getting the numerical figure . 1 12 123 1234 12345plse help me.i am writing these following logic:# include void main(){ int i,j;for(i=0;i<=5;i++){ for(j=1;j #include int main(int argc, char * argv[]) or just: int main() { for(int i(0); i < 6; i++) Why start at 0? And there's nothing wrong with initialization using =. Most people would write this as: for (int i = 1; i <= 5; ++i) // (or i++, it doesn't matter here) { for(int j(1); j < i + 1; j++) std::cout << j; Why put the loop body on the same line? That makes it difficult to debug. (It also goes against your "easier to read" statement above, in my opinion.) How about: for (int j = 1; j <= i; ++j) You seem to not like using <= for comparisons. I'm guessing this is because you've heard that it's quicker to compare using < than <=? While it _may_ be that in some case of un-optimized code, using <= might take more machine cycles, it seems more readable to me to use <=, because that shows your actual upper bound right there in the code, without having to mentally subtract one to get the real upper bound. (Also, in cases where the compiler isn't optimizing the loop anyway, the use of i+1 would mean an extra step of adding 1 every iteration before comparing, negating your assumed speedup from using < instead of <=.) std::cout << std::endl; } } Oct 2 '06 #3

 P: n/a "Advait Vaidya" i am not getting the numerical figure . 1 12 123 1234 12345 plse help me. i am writing these following logic: # include void main() int main() You always need to specify int as the return type from main, if you want to write C++ code according to the standard. Some compilers allow void, but it's wrong. { int i,j; for(i=0;i<=5;i++) Why start at 0? You want 5 lines, you should have 5 counts: 1,2,3,4,5. { for(j=1;j

 P: n/a Howard wrote: > "imperfectfreak" Try writing code that is a little neater and easier to read. Also don't use depreciated headers. You mean "deprecated", right? It should be pointed out that iostream.h isn't a deprecated header, it's completely non-standard. Brian Oct 2 '06 #5

 P: n/a Default User wrote: Howard wrote: >>"imperfectfreak" Try writing code that is a little neater and easier to read. Also don't use depreciated headers. You mean "deprecated", right? It should be pointed out that iostream.h isn't a deprecated header, it's completely non-standard. It never has been a standard header, so when only looking at the standard, you're right. However, on some actual implementations (like GCC e.g.), it does exist, but is deprecated. Oct 3 '06 #6

### This discussion thread is closed

Replies have been disabled for this discussion.