Odd and square numbers: Difference between revisions
Added C
Not a robot (talk | contribs) (Add 8080 Assembly) |
(Added C) |
||
Line 208:
Here it's known that the final output should have the transformation <code>ט1+2×⊢</code> applied to it to produce odd squares. The reverse of this transformation is applied to the two bounds 100 and 1000, then <code>↓⟜↕</code> produces a numeric range which is transformed back.
=={{header|C}}==
{{trans|Wren}}
<syntaxhighlight lang="c">#include <stdio.h>
#include <math.h>
int main() {
int i, p, low, high, pow = 1, osc;
int oddSq[120];
for (p = 0; p < 5; ++p) {
low = (int)ceil(sqrt((double)pow));
if (!(low%2)) ++low;
pow *= 10;
high = (int)sqrt((double)pow);
for (i = low, osc = 0; i <= high; i += 2) {
oddSq[osc++] = i * i;
}
printf("%d odd square from %d to %d:\n", osc, pow/10, pow);
for (i = 0; i < osc; ++i) {
printf("%d ", oddSq[i]);
if (!((i+1)%10)) printf("\n");
}
printf("\n\n");
}
return 0;
}</syntaxhighlight>
{{out}}
<pre>
Same as Wren example.
</pre>
=={{header|CLU}}==
|