課題について
Posted: 2022年11月15日(火) 07:37
x^2+y^2<=1.0となる場合の数ncountをカウントする。
このプログラミングが分かりません。よろしくお願いします。
このプログラミングが分かりません。よろしくお願いします。
#include <stdio.h>
#include <stdlib.h>
int
main(void) try
{
int ncount = 0;
for (int yy = -15; yy < 15; yy++) {
const double y = (double)yy / 10;
for (int xx = -15; xx < 15; xx++) {
const double x = (double)xx / 10;
if( x*x + y*y <= 1.0 ){
printf("@ ");
}
else {
printf(". ");
}
}
printf( "\n" );
}
return EXIT_SUCCESS;
}
catch (...) {
return EXIT_FAILURE;
}
// end.
#include <stdio.h>
#include <stdlib.h>
__forceinline unsigned char
MandelCount( const float x, const float y )
{
float cx = x;
float cy = y;
float sqx, sqy;
unsigned char n = 0;
do
{
sqy = cy * cy; // y^2
cy += cy;
cy *= cx;
cy += y; // 2 * x * y + y0
sqx = cx * cx; // x^2
cx = sqx - sqy + x; // x^2 - y^2 + x0
--n;
if (n == 0) {
return 0;
}
} while (sqx + sqy < 4.0f);
return n;
}
int
main(void) try
{
for (int yy = -15; yy < 15; yy++) {
const float y = (float)yy / 10;
for (int xx = -15; xx < 15; xx++) {
const float x = (float)xx / 10;
printf("%c ", " 123456789"[ MandelCount(x, y) % 10]);
}
printf( "\n" );
}
return EXIT_SUCCESS;
}
catch (...) {
return EXIT_FAILURE;
}
// end.