Distinct power numbers: Difference between revisions

Add C
(Add BCPL)
(Add C)
Line 156:
wrch('*N')
$)</lang>
{{out}}
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
 
=={{header|C}}==
<lang c>#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int compare(const void *a, const void *b) {
int ia = *(int*)a;
int ib = *(int*)b;
return (ia>ib) - (ia<ib);
}
 
int main() {
int pows[16];
int a, b, i=0;
for (a=2; a<=5; a++)
for (b=2; b<=5; b++)
pows[i++] = pow(a, b);
qsort(pows, 16, sizeof(int), compare);
for (i=0; i<16; i++)
if (i==0 || pows[i] != pows[i-1])
printf("%d ", pows[i]);
printf("\n");
return 0;
}</lang>
{{out}}
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
2,096

edits