C++“while”循环语句完成题目

第一题、

int main()
{
	int a=1000;
	while(a<10000)
	{
		int q=a/1000;
		int b=a/100%10;
		int s=a/10%10;
		int g=a%10;
		if(((10*q+b)+(10*s+g))*((10*q+b)+(10*s+g))==a)
		{
			cout<<a<<endl;
		}
		a++;
	}
	system("pause");
	return 0;
} 

 第二题、

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a=1;
	while(1<=a&&a<=500)
	{
		if(a%3==2&&a%5==3&&a%7==2)
		{
			cout<<a<<endl;
		}
		a++;
	}
	system("pause");
	return 0;
} 

 第三题、

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int b=1;
	int c=1;
	while(b<=a)
	{
		c=c*b;
		b++;
	}
	cout<<c<<endl;
	system("pause");
	return 0;
} 

 第四题、

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int b=0;
	int c=100;
	while(c>=1)
	{
		b=b+c;
		c=c-3;
	}
	cout<<b<<endl;
	system("pause");
	return 0;
} 

第五题、

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int b=0;
	int c=1;
	while(c<=n)
	{
		b=b+c;
		c++;
	}
	cout<<b<<endl;
	system("pause");
	return 0;
}

第六题、

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int b=0;
	int c=1;
	if(n%2!=0)
	{
		while(c<=n)
	{
		b=b+c;
		c=c+2;
	}
	cout<<b<<endl;
	}
	system("pause");
	return 0;
}

  

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值