//求n以内(不包括n)同时能被3和7整除的所有自然数之和的平方根s,
//并作为函数值返回。例如若n为1000时,函数值应为:s=153.909064。
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
double f(int x)
{
double sum=0;
for(int i=3;i<x;i++)
{
if(i%3==0&&i%7==0)
sum+=i;
}
return sum;
}
int main()
{
int n;
while(cin>>n)
cout<<setw(20)<<setprecision(9)<<sqrt(f(n))<<endl;//setw设置宽度setprecision设置精度
return 0;
}
//倒序输出
#include<iostream>
using namespace std;
int f(int n)//返回值
{
int t,res=0;
while(n>0)
{
t=n%10;
res=res*10+t;
n/=10;
}
return res;
}
void ff(int &n)//引用
{
int t,res=0;
while(n>0)
{
t=n%10;
res=res*10+t;
n/=10;
}
n=res;
}
void fff(int *n)//指针
{
int t,res=0;
while(*n>0)
{
t=*n%10;
res=res*10+t;
*n/=10;
}
*n=res;
}
int main()
{
int a,b,c;
while(cin>>a>>b>>c)
{
cout<<f(a)<<endl;
ff(b);
cout<<b<<endl;
fff(&c);
cout<<c<<endl;
}
return 0;
}
1
最新推荐文章于 2024-04-26 13:06:48 发布