Login
|
Signup
langref.org
-
csharp
,
clojure
, and
cpp
add..
all
erlang
fantom
fsharp
go
groovy
haskell
java
ocaml
perl
php
python
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Structure
Loops
Perform an action multiple times based on a boolean condition, checked before the first action (WHILE .. DO)
Starting with a variable x=1, Print the sequence
"1,2,4,8,16,32,64,128,"
by doubling x and checking that x is less than 150.
csharp
int x = 1;
while (x < 150)
{
x *= 2;
Console.Write("{0},", x);
}
int x = 1;
while (x < 150)
{
x *= 2;
Console.Write("{0},", x);
}
clojure
(take-while #(< % 150) (iterate #(* 2 %) 1))
(take-while #(< % 150) (iterate #(* 2 %) 1))
cpp
C++/CLI .NET 2.0
int x = 1;
while (x < 150) { x *= 2; Console::Write("{0},", x); }
Console::WriteLine();
using namespace System;
int main()
{
int x = 1;
while (x < 150) { x *= 2; Console::Write("{0},", x); }
Console::WriteLine();
}
cpp
for (int x = 1; x < 150; x *= 2) { std::cout << x << ","; }
std::cout << std::endl;
int main()
{
for (int x = 1; x < 150; x *= 2) { std::cout << x << ","; }
std::cout << std::endl;
}
Submit a new solution for
csharp
,
clojure
, or
cpp
There are 16 other solutions in
additional
languages (
erlang
,
fantom
,
fsharp
,
groovy
...)