二次函数程序c语言,二次函数c语言函数编写
用c语言画一个2次函数图像
#include windows.h
专注于为中小企业提供网站设计制作、网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业云城免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[]=TEXT("二次函数");
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("二次函数"),
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);
}
帮我看看求二次函数的C语言程序,要求要用函数来写,谢了
我已经按你的意思修改了,也运行出来了,希望对你有帮助,代码附带在下面:
#includestdio.h
#includemath.h
float t,x1,x2;
void main()
{
void situ1(float a,float b,float c);
void situ2(float a,float b,float c);
void situ3();
float x,a,b,c;
scanf("%f%f%f",a,b,c);
if (a==0)
{
x=-c/b;
printf("x=%.2f\n",x);
}
else
{
t=b*b-4*a*c;
if (t0)
situ1(a,b,c);
else if(t==0)
situ2(a,b,c);
else
situ3();
}
}
void situ1(float a,float b,float c)
{
x1=(-b+sqrt(t))/(2*a);
x2=(-b-sqrt(t))/(2*a);
printf("x1=%.2f\tx2=%.2f\n",x1,x2);
}
void situ2(float a,float b,float c)
{
x1=x2=(-b+sqrt(t))/(2*a);
printf("x1=x2=%.2f\n",x1);
}
void situ3()
{
printf("没有实根\n");
}
C语言怎样设计二次函数,请各位哥哥姐姐帮帮忙,
#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);
m=b*b-4*a*c;
if(m=0a!=0){
if(m0){
x1=(-b+sqrt(m))/(2*a);
x2=(-b-sqrt(m))/(2*a);
printf("两根\n");
printf("x1=%f\n",x1);
printf("x2=%f\n",x2);}
else
printf("一根\n");
printf("x1=x2=%f\n",x1);}
else
{
if(a=0 b!=0) printf("根是x=-c/b");
if(a=0b=0) printf("为常函数");
if(a!=0) printf("无根\n");
}
system("PAUSE");
return 0; }
c语言:求二次函数ax^2+bx+c=0的根
#include stdio.h
#include math.h
void main()
{
float a,b,c,x1,x2,p,q,disc;
printf("input a,b,c\n");
scanf("a=%f,b=%f,c=%f",a,b,c);
disc=b*b-4*a*c;
if (disc0)
{
printf("没根\n");
}
else
{
p=-b/(2*a);
q=sqrt(disc)/(2*a);
x1=p+q;
x2=p-q;
printf("\nx1=%5.2f\nx2=%5.2f\n",x1,x2);
}
}
你输入的那个方程根本就没有根,这个你需要加一个判断条件,这样才能正确处理求根公式
C语言写二次函数
首先你已经很清楚的说明了你这个程序是用C语言写二次函数的,而当a=0时,就不是二次函数了,应该按照一次函数来进行计算,否则 一个数除以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("无实根\n");
}
return 0;
}
c语言解答二次函数
这个简单啊
#includestdio.h
#includemath.h
main()
{
double a,b,c,w;
printf("请输入三个数(方程的系数),中间用空格分开\n");
scanf("%lf%lf%lf",a,b,c);
w=b*b-4*a*c;
if (w0)printf("方程无解\n");
else if(w==0)printf("方程有一个解:x=%lf\n",-b/(2*a));
else printf("方程有两个解:x1=%lf,x2=%lf\n",(-b+sqrt(w))/(2*a),(-b-sqrt(w))/(2*a));
}
网站栏目:二次函数程序c语言,二次函数c语言函数编写
浏览地址:http://scyanting.com/article/hegihp.html