+ 3
How to print 1 to 100 without any loop and without any recursion
19 Antworten
+ 16
int x=1;
if (x !=100)
System.out.println (x++);
// an idea ☺ , will it work sir
//wait ,thinking ...
+ 15
pranit , post codes(java) on it , if u got the solution so that everyone can see (including me) ☺
//i am waiting
+ 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.
+ 5
Sure there is, try printing every single number...😀
+ 4
@David got it bro..
got 2 new approaches for this program..
thank you so much...
+ 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];
}
+ 3
Console.Write ("1 to 100");
//this prints 1 to 100 but not 1 2 3 4 ...100
+ 3
0xDEADBEEF,
thanx bro it's working
+ 2
any other way? @tobias
+ 2
@ Tobias asked in interviews🤔
+ 2
yes goto is one way but they rejected my ans using goto saying indirectly it is loop only
+ 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 :)
+ 2
Siva,
yes that's right
but we want number from 1 to 100
:)
+ 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.
+ 1
@gaurav it will print only 1
what about other number from 2 to 100?
if condition implements only 1 time
+ 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