[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Hey Folks, i have to create a program which tells me the power

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 9
Thread images: 4

File: 5.png (23KB, 900x1600px) Image search: [Google]
5.png
23KB, 900x1600px
Hey Folks,
i have to create a program which tells me the power set of numbers between 0 and 10.
if the user says things out of the range, he will get asked again.
if the user types in 2, the program has to count from 0 to 2 and has to tell all the power sets
e.g.: { { }, { 0 }, { 1 }, { 0, 1 }, { 2 }, { 0, 2 }, { 1, 2 }, { 0, 1, 2 } }

pic related, the fundament
could anyone help?
>>
File: Untitled.png (13KB, 1080x1920px) Image search: [Google]
Untitled.png
13KB, 1080x1920px
>>57736478
>>
#include <stdio.h>
#include <math.h>

void printPowerSet(char *set, int set_size)
{
/*set_size of power set of a set with set_size
n is (2**n -1)*/
unsigned int pow_set_size = pow(2, set_size);
int counter, j;

/*Run from counter 000..0 to 111..1*/
for(counter = 0; counter < pow_set_size; counter++)
{
for(j = 0; j < set_size; j++)
{
/* Check if jth bit in the counter is set
If set then pront jth element from set */
if(counter & (1<<j))
printf("%c", set[j]);
}
printf("\n");
}
}

/*Driver program to test printPowerSet*/
int main()
{
char set[] = {'a','b','c'};
printPowerSet(set, 3);

getchar();
return 0;
}

took like 30 seconds, kill yourself OP
>>
In Haskell this is just
import Data.List
powerSet n = subsequences [0..n]


Hope this helps.
>>
let power_set n =
let rec loop = function
| -1 -> [[]]
| n ->
let ps = loop (pred n) in
let rec inner_loop accu = function
| [] -> accu
| p :: ps -> inner_loop (p :: (n :: p) :: accu) ps in
inner_loop [] ps in
loop n
;;
>>
File: 1473946527764.png (214KB, 579x307px) Image search: [Google]
1473946527764.png
214KB, 579x307px
>>57736569
>loops instead of goto
>>
>>57737140
>2016
>using goto

Lol ok grandpa. Show me any improvement and I'll show you my dick
>>
File: 1430922332866.png (21KB, 900x900px) Image search: [Google]
1430922332866.png
21KB, 900x900px
>>57736478
how you can learn to code if you cant even make a screenshot right
>>
lmao
Thread posts: 9
Thread images: 4


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.