在c的標(biāo)準(zhǔn)庫中有g(shù)raphic.h頭文件,實(shí)現(xiàn)了很多畫圖函數(shù) 比如 lineto, moveto, arc,(函數(shù)名可能記錯,好久沒用了-.-!)
創(chuàng)新互聯(lián)建站從2013年創(chuàng)立,先為彭陽等服務(wù)建站,彭陽等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為彭陽企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
直線:起點(diǎn)加終點(diǎn)就行。
二次曲線,比如拋物線,那就以定長拆分成小直線。雙曲線同理。
拋物線,和雙曲線用定長拆分,估計(jì)很難計(jì)算。要是精度要求不高就根據(jù)情況改成定x,或者定y偏移的拆分,要是精度要求高那就去找直線擬合曲線的算法或者雙圓弧擬合曲線的算法。
#include?windows.h
LRESULT?CALLBACK?WndProc(HWND,?UINT,?WPARAM,?LPARAM);
int?WINAPI?WinMain(HINSTANCE?hInstance,?HINSTANCE?hPrevInstance,
PSTR?szCmdLine,?int?iCmdShow)
{
static?TCHAR?szAppName[]=TEXT("二次函數(shù)");
HWND?????????hwnd;
MSG??????????msg;
WNDCLASS?????wndclass;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,?IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,?IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName;
if?(!RegisterClass(wndclass))
{
MessageBox(NULL,?TEXT("Error"),
szAppName,?MB_ICONERROR);
return?0;
}
hwnd=CreateWindow(szAppName,?TEXT("二次函數(shù)"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,?CW_USEDEFAULT,
CW_USEDEFAULT,?CW_USEDEFAULT,
NULL,?NULL,?hInstance,?NULL);
ShowWindow(hwnd,?iCmdShow);
UpdateWindow(hwnd);
while?(GetMessage(msg,?NULL,?0,?0))
{
TranslateMessage(msg);
DispatchMessage(msg);
}
return?msg.wParam;
}
LRESULT?CALLBACK?WndProc(HWND?hwnd,?UINT?message,?WPARAM?wParam,?LPARAM?lParam)
{
static?int??cxClient,?cyClient;
const?static?int?n=1000;
HDC?????????hdc;
int?????????i;
PAINTSTRUCT?ps;
POINT???????apt[n];
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);
MoveToEx(hdc,?cxClient/2,?0,?NULL);
LineTo(hdc,?cxClient/2,?cyClient);
for?(i=0;?i??n;++i)
{
apt[i].x=cxClient/4+i; apt[i].y=cyClient-(cyClient/2-i)*(cyClient/2-i)/300-cyClient/2+100;
}
Polyline(hdc,?apt,?n);
return?0;
case?WM_DESTROY:
PostQuitMessage(0);
return?0;
}
return?DefWindowProc(hwnd,?message,?wParam,?lParam);
}
首先你已經(jīng)很清楚的說明了你這個程序是用C語言寫二次函數(shù)的,而當(dāng)a=0時,就不是二次函數(shù)了,應(yīng)該按照一次函數(shù)來進(jìn)行計(jì)算,否則 一個數(shù)除以0就沒有意義了.~
#include stdio.h
#include stdlib.h
#include math.h
int main()
{
float a,b,c;
float x1,x2,m;
printf("input number a=:");
scanf("%f",a);
printf("input number b=:");
scanf("%f",b);
printf("input number c=:");
scanf("%f",c);
if(a==0)
printf("一根:%f\n",c*(-1)/b);
else if(a==0b==0)
printf("無意義!");
else
{
m=b*b-4*a*c;
if(m0)
{
printf("兩根\n");
printf("x1=%f\n",(-b+sqrt(m))/(2*a));
printf("x2=%f\n",(-b-sqrt(m))/(2*a));
}
else if(m==0)
printf("x1=x2=%f\n",x1);
}
else
printf("無實(shí)根\n");
}
return 0;
}
C語言是面向過程的一種語言,換句話說,他只關(guān)心如何解決問題,如何以更短的時間和更少的空間解決問題,至于答案以怎樣的形式表現(xiàn)出來,那就不是C語言要考慮的東西了。你可以直接把答案輸出到屏幕上,也可以把它輸出到一個文件中。如果涉及到作圖一類的問題,你可以選擇Turbo C,或者JAVA。