求二次函数的极值
// test1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(int argc, char* argv[])
{
printf("Hello World!\n");
int a,b,c;
float x,value;
puts("y=ax^2+bx+c,please input a,b,c");
puts("a=");
scanf("%d",&a);
puts("b=");
scanf("%d",&b);
puts("c=");
scanf("%d",&c);
if(a>0)
{
puts("function has the smallest value,which is");
x=(float)b/(float)(2*a);
x=-x;
value=a*x*x+b*x+c;
printf("%f",value);
}
else
{
puts("function has the biggest value,which is");
x=(float)(b)/(float)(a)/2;
x=-x;
value=a*x*x+b*x+c;
printf("%f",value);
}
return 0;
}