1. 程式人生 > >如何保留小數點後任意一位數

如何保留小數點後任意一位數

orm CI 小數 ans for names include ace #define

#include<iostream>
#include<cstring>
#include<cmath>
#define pi 3.14159265
using namespace std;
int main()
{
char format[10]={0};
int t;
cin>>t;
while(t--)
{
long long n,x;
scanf("%lld%lld",&n,&x);//求n的Pi次方,並且輸出小數點後x位
sprintf(format,"%%.%dlf",x);
double ans;
ans=1.0*pow(n,pi);
printf(format,ans);
cout<<endl;
}
return 0;
}

如何保留小數點後任意一位數