码迷,mamicode.com
首页 > 其他好文 > 详细

如何保留小数点后任意一位数

时间:2018-05-06 17:28:55      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:name   return   sprint   end   cin   ble   cst   cout   clu   

#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;
 }

如何保留小数点后任意一位数

标签:name   return   sprint   end   cin   ble   cst   cout   clu   

原文地址:https://www.cnblogs.com/caijiaming/p/8998813.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!