C++作业

1、爱因斯坦出了一道这样的数学题:有一条长阶梯,若每步跨2阶,则最后剩一阶,若每步跨3 阶,则最后剩2阶,若每步跨5阶,则最后剩4阶,若每步跨6阶,则最后剩5阶。只有每次跨7阶,最后才正好一阶不剩。请问这条阶梯最少共有多少阶?

#include <iostream>
using namespace std;
int main()
{
	int n;
	n=1;
	while(1)
	{
		if (n % 2 == 1 && n % 3 == 2 && n % 5 == 4 && n % 6 == 5 && n % 7 == 0)
		{
			cout<<n<<endl;
			break;
		}	
		n++;
	}
	
}

2、求恰好使s=1+1/2+1/3+...+1/n的值大于X时n的值。(2<=x<=10)

#include<iostream>
using namespace std;
int main() 
{
	int X;
	double n=1,sum=0;
	cin>>X;
	while(n)
	{
		sum+=1.0/n;
		if(sum>X)
		{
			break;
		}
		n++;
	}
	cout<<n;
    return 0;
}

3、角谷猜想

#include <iostream>
using namespace std;
int main()
{
    int n,x;
    cin>>n;
    while(n!=1)
    {
        if(n%2!=0)
        {
            n=n*3+1;
            x++;
        }
        else
        {
            n=n/2;
            x++;
        }
    }
    cout<<x;
    return 0;
}

4、小明开心的在游泳,可是他很快难过的发现,自己的力气不够,游泳好累哦。已知小明每换一次气能游2米,可是随着越来越累,力气越来越小,他接下来的每换一次气都只能游出上一步距离的98%。求要游到距离x米的地方,他需要总共换多少次气

#include<bits/stdc++.h>
using namespace std;
int main()
{
	float x,sum=2,a=2;
	int i=1;
	cin>>x;
	while(sum<x)
	{
		sum=sum+a;
		a=a*0.98;
		i++;
	}
	cout<<i<<endl;
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值