You make a fair point.
Code:print('\n'.join(str(tier) for tier in [' '.join(str(i*j) for i in range(1, j+1)) for j in range(1, 11)]))
Printable View
You make a fair point.
Code:print('\n'.join(str(tier) for tier in [' '.join(str(i*j) for i in range(1, j+1)) for j in range(1, 11)]))
I see your point, but then using one for loop was about the only thing that was clarified, so I think most of us assumed it was mandatory. My alternative suggestion, before everyone started talking about their solutions for printing that string was to post something like this:
This might, in fact, be a more correct solution to the OP's question if they meant quite literally:Code:#include <stdio.h>
int main() {
int i;
for (i=0; !i; i++)
return 0;
}
Any use of one of those numbers might be considered inaccurate. In fact, I chose to be even more pedantic by using !i as every positive digit from 1-9 is present by itself in the OP's sequence which one could argue disallows any number that contains them. Though, of course, there are other ways of do a for loop without using any of those numbers, as well. I wasn't actually sure if a blank for(;;) was legal by the C standard or if it was just the compiler I was using, but I probably would have preferred that if it was.Quote:
CAN ANYONE HELP ME to write a c program using only "one for loop" and without using a 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 64 9 18 27 36 45 54 63 72 81 10 20 30 40 50 60 70 80 90 100
Ah, in that case, I would propose this two line C99 program:
Code:int main(void) {
for (; 0;); }
Yeah that's about as compact as it gets. I should really feel silly for leaving in my compiler's templated #include <stdio.h> in a program that wasn't calling any library functions.
I accept that you abandoned the "using C" requirement, but I can't forgive you for technically using more than one for.
Eh. I guess it could be fixed. I suspect people would get bored of me though.