绝霸天下全本下载:用*表示出0--360度之间的COSX的曲线图象

来源:百度文库 编辑:中科新闻网 时间:2024/04/30 12:42:28

C:
//test.c
#include <math.h>
#define PI 3.1415926

int main(){
double angle;
int i,x,y,w = 80, h = 29, len = (w+1)*h;
char* str = (char*)malloc(len+1);
memset(str,' ',len);
for( i = w; i <= len; i += w+1) str[i]='\n';
str[len] = 0;

for (x = 0; x < w; x ++){
angle = (x * 2 * PI) / w;
y = (int)(round(cos(angle) * (h/2)));
str[(h/2-y)*(w+1)+x]='*';
}
printf(str);
}

java:
Test.java
public class Test {
public static void main(String[] args){
double angle;
int i,x,y,w = 80, h = 29, len = (w+1)*h;
char[] str = new char[len];
for( i = str.length-1; i >= 0; i -- ) str[i] = ' ';
for( i = w; i <= len; i += w+1) str[i]='\n';

for (x = 0; x < w; x++) {
angle = (x * 2 * Math.PI) / w;
y = (int) (Math.round(Math.cos(angle) * (h / 2)));
str[(h / 2 - y) * (w + 1) + x] = '*';
}
System.out.println(str);
}
}