栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++程设第三次作业 循环结构(勉强写完版)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++程设第三次作业 循环结构(勉强写完版)

1. 输出100—1000之间能被3整除或个位是3的整数,每行输出10个。(用while)

#include                                                  
using namespace std;               
int main()
{int a,i;
a=1;
	for(i=100;i<=1000;i++){
		if(i%3==0||i%10==3){
			if (a==10){
			cout< 

2. 对于任一整数n,输出其所有的因子。 (如12的因子为: 1,2,3,4,6,12)

#include                                                  
using namespace std;               
int main()
{int n,i;
  cin>>n;
  for(i=1;i<=n;i++){
  	if(n%i==0){
  		cout< 

3. 输入一个数,统计该数的位数。(用do- while)(这大概就是作业吧)

#include                                                  
using namespace std;               
int main()
{int a,i;
cin>>a;
i=0;
do{
	a=a/10;
	i++;
} while(a>0);
cout< 

4. 输出1000内的完数。(完数是指其因子(不含本身)之和与本身相等的数,如6是完数, 6 =1+2+3)

#include                                                  
using namespace std;               
int main()
{int n,i,k;
for(n=6;n<=1000;n++){
	k=1;
  for(i=2;i<=n/2;i++){
  	if(n%i==0){
  		k=k+i;
	  }
  }
  if(k==n){
  	cout< 

5. 用级数算法求圆周率PI的近似值。(呼呼)

#include
#include
#include
using namespace std;
int main()
{
int s = 1;
double n = 1, t = 1, pi = 0;
while ((fabs(t))>1e-8)
{
pi = pi + t;
n = n + 2;
s = -s;
t = s / n;
}
pi = pi * 4;
cout << setiosflags(ios::fixed) << setprecision(6) << pi << endl;
system("pause");
return 0;
}

6. 输入一正整数,输出其逆序数。(如输入1234,输出4321)

#include
using namespace std;
int main(){
int a,b;
cin >> a ;
while(a!=0){
b=b*10+a%10;    //别问 问就是抄的
a=a/10;}
cout << b << endl;
    return 0;
}

7. 输入两个正整数a和n,求a+aa+aaa+aaaa+a…a(n个)之和。 (如输入2,3,计算2+22+222之和,输出246)(这个查了好久的资料ww)

#include
#include
using namespace std;
int main(){
int a,b,n,i,j;
cin >> a >>n;
for(i=n;i>0;i--){
	for(j=i;j>0;j--){
		b=b+a*pow(10,j-1);
	}
}
cout< 

8. 冒泡排序(典中典了 不放了)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/396319.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号