这个简单的C++程序哪里错了?

来源:百度知道 编辑:UC知道 时间:2024/06/20 13:53:49
我想让它输出二位小数,错在了输出格式上面,但是我不知道怎么改,谢谢高手了
#include<iostream.h>
#include<math.h>
void main()
{
float x,y;
cin>>x;
if(x<=0) y=-x;
if(x>0&&x<10) y=x*x;
if(x>=10) y=sqrt(x);

cout<<%.2f<<y<<endl ;
}

#include<iostream.h>
#include<math.h>

#include <iomanip.h>

void main()
{
float x,y;
cin>>x;
if(x<=0) y=-x;
if(x>0&&x<10) y=x*x;
if(x>=10) y=sqrt(x);

cout<< setiosflags(ios::fixed) << setprecision(2) << y <<endl ;

}

#include"stdio.h"

printf("%2f",y);