+ 3

How to print 1 to 100 without any loop and without any recursion

18th Oct 2017, 8:05 AM
Pranit Gandhi
Pranit Gandhi - avatar
19 Respuestas
+ 16
int x=1; if (x !=100) System.out.println (x++); // an idea ☺ , will it work sir //wait ,thinking ...
18th Oct 2017, 8:30 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 15
pranit , post codes(java) on it , if u got the solution so that everyone can see (including me) ☺ //i am waiting
18th Oct 2017, 8:48 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 7
using template check out here, http://www.geeksforgeeks.org/output-of-c-program-set-18-3/ you can also define a function for doing the incrementation.
18th Oct 2017, 8:38 AM
David Fernando
David Fernando - avatar
+ 5
Sure there is, try printing every single number...😀
19th Oct 2017, 3:53 PM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
+ 4
@David got it bro.. got 2 new approaches for this program.. thank you so much...
18th Oct 2017, 8:43 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 4
#include <iostream> class cl { public: cl() { static size_t sCounter = 0; std::cout << ++sCounter << "\n"; } }; int main() { constexpr size_t upper_bound = 100; cl c[upper_bound]; }
18th Oct 2017, 8:52 AM
aklex
aklex - avatar
+ 3
Console.Write ("1 to 100"); //this prints 1 to 100 but not 1 2 3 4 ...100
18th Oct 2017, 8:55 AM
Siva Shankar
Siva Shankar - avatar
+ 3
0xDEADBEEF, thanx bro it's working
18th Oct 2017, 8:55 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 2
any other way? @tobias
18th Oct 2017, 8:28 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 2
@ Tobias asked in interviews🤔
18th Oct 2017, 8:30 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 2
yes goto is one way but they rejected my ans using goto saying indirectly it is loop only
18th Oct 2017, 8:35 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 2
Gaurav, up till now I don't have any ans (code) for this but with David link I got logic so I will try upon that if I got new logic definitely I will post it :)
18th Oct 2017, 8:50 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 2
Siva, yes that's right but we want number from 1 to 100 :)
18th Oct 2017, 8:57 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 2
@Martin Taylor It's not about "deep knowledge". It's about how well you do if you are thrown an unexpected bone and whether or not you can come up with a solution on your feet.
19th Oct 2017, 1:20 AM
aklex
aklex - avatar
+ 1
@gaurav it will print only 1 what about other number from 2 to 100? if condition implements only 1 time
18th Oct 2017, 8:32 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 1
@Siva don't know.. you try it and tell us weather it is working or not.. if it will work we will get new approach for this program
18th Oct 2017, 8:47 AM
Pranit Gandhi
Pranit Gandhi - avatar