用代码写生日祝福——送给好女孩
还有一周我女朋友的生日要到了,我突发奇想:想用C语言编一个小程序出来,作为她的生日礼物。但是我现在只会一些皮毛,我个人想的是去编一个图案出来,或者一个动态的“Happy birthday”or 简单的对话系统,毕竟能力有限,各位好友有什么好的建议和想法,可以提出来哈!谢谢了! 哦,对,以前也接触了点单片机的知识,如果时间来得及的话,写一个简单的程序,然后用蜂鸣器发音或者利用数码管显示内容... 总之,能想到的就这些了,麻烦各位了!!!
2016-03-22 02:10
2016-03-22 08:09

2016-03-22 09:27

2016-03-22 09:30
2016-03-22 09:49

2016-04-23 06:24
2016-04-24 17:39
2016-04-25 02:01

程序代码:#include <stdio.h>
#include <math.h>
float f(float x, float y, float z) {
float a = x * x + 9.0f / 4.0f * y * y + z * z - 1;
return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z;
}
float h(float x, float z) {
for (float y = 1.0f; y >= 0.0f; y -= 0.001f)
if (f(x, y, z) <= 0.0f)
return y;
return 0.0f;
}
int main() {
for (float z = 1.5f; z > -1.5f; z -= 0.05f) {
for (float x = -1.5f; x < 1.5f; x += 0.025f) {
float v = f(x, 0.0f, z);
if (v <= 0.0f) {
float y0 = h(x, z);
float ny = 0.01f;
float nx = h(x + ny, z) - y0;
float nz = h(x, z + ny) - y0;
float nd = 1.0f / sqrtf(nx * nx + ny * ny + nz * nz);
float d = (nx + ny - nz) * nd * 0.5f + 0.5f;
putchar(".:-=+*#%@"[(int)(d * 5.0f)]);
}
else
putchar(' ');
}
putchar('\n');
}
}

2016-04-28 08:01
2016-04-28 08:23