69,373
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
#include <math.h>
#define NUM 1000
#define TWOPI 6.283185
TCHAR szAppName[] = TEXT("SineWave");
HWND hwnd;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL InitApplication(HINSTANCE);
void InitInstance(HINSTANCE, int);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
MSG msg;
if (!hPrevInstance)
if (!InitApplication(hInstance))
return FALSE;
InitInstance(hInstance, nShowCmd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
BOOL InitApplication(HINSTANCE hinstance)
{
WNDCLASS ws;
ws.style = CS_VREDRAW | CS_HREDRAW;
ws.lpfnWndProc = WndProc;
ws.cbWndExtra = 0;
ws.cbClsExtra = 0;
ws.hInstance = hinstance;
ws.hIcon = LoadIcon(NULL, IDI_APPLICATION);
ws.hCursor = LoadCursor(NULL, IDC_ARROW);
ws.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
ws.lpszMenuName = NULL;
ws.lpszClassName = szAppName;
return (RegisterClass(&ws));
}
void InitInstance(HINSTANCE hinstance, int nCmdShow)
{
hwnd = CreateWindow(szAppName, TEXT("Sine Wave Using Polyline"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_US
EDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hinstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClient, cyClient;
HDC hdc;
int i;
PAINTSTRUCT ps;
POINT apt[NUM];
switch (message)
{
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
MoveToEx(hdc, 0, cyClient / 2, NULL);
LineTo(hdc, cxClient, cyClient / 2);
for (i = 0; i < NUM; ++i)
{
apt[i].x = i * cxClient / NUM;
apt[i].y = (int)(cyClient / 2 * (1 - sin(TWOPI * i / NUM)));
}
Polyline(hdc, apt, NUM);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
#include<stdio.h>
#include<math.h>
main(){
double y;
int x,m,i;
printf("y=sin(x) [0<x<2*pi]\n");
for(y=1;y>=-1;y-=0.1){
if(y>=0){
m=asin(y)*10;
for(x=1;x<m;x++)printf(" ");
printf("*",m);
for(;x<31-m;x++)printf(" ");
printf("*\n");}
else{
m=-1*asin(y)*10;
for(i=0;i<32;i++)printf(" ");
for(x=1;x<m;x++)printf(" ");
printf("*",m);
for(;x<31-m;x++)printf(" ");
printf("*\n",m);
}
}
}