return0;
}
3.15题
#include
usingnamespacestd;
intmain()
{intp,r,n,m,temp;
cout<<"pleaseentertwopositiveintegernumbersn,m:
";
cin>>n>>m;
if(n{temp=n;
n=m;
m=temp;//把大数放在n中,小数放在m中
}
p=n*m;//先将n和m的乘积保存在p中,以便求最小公倍数时用
while(m!
=0)//求n和m的最大公约数
{r=n%m;
n=m;
m=r;
}
cout<<"HCF="<cout<<"LCD="<
return0;
}
3.16题
#include
usingnamespacestd;
intmain()
{charc;
intletters=0,space=0,digit=0,other=0;
cout<<"enteroneline:
:
"<while((c=getchar())!
='\n')
{if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
elseif(c=='')
space++;
elseif(c>='0'&&c<='9')
digit++;
else
other++;
}
cout<<"letter:
"<"<"<other:
"<return0;
}
3.17题
#include
usingnamespacestd;
intmain()
{inta,n,i=1,sn=0,tn=0;
cout<<"a,n=:
";
cin>>a>>n;
while(i<=n)
{tn=tn+a;//赋值后的tn为i个a组成数的值
sn=sn+tn;//赋值后的sn为多项式前i项之和
a=a*10;
++i;
}
cout<<"a+aa+aaa+...="<return0;
}
3.18题
#include
usingnamespacestd;
intmain()
{floats=0,t=1;
intn;
for(n=1;n<=20;n++)
{
t=t*n;//求n!
s=s+t;//将各项累加
}
cout<<"1!
+2!
+...+20!
="<
return0;
}
3.19题
#include
usingnamespacestd;
intmain()
{inti,j,k,n;
cout<<"narcissusnumbersare:
"<for(n=100;n<1000;n++)
{i=n/100;
j=n/10-i*10;
k=n%10;
if(n==i*i*i+j*j*j+k*k*k)
cout<}
cout<return0;
}
3.20题
#include
usingnamespacestd;
intmain()
{constintm=1000;//定义寻找范围
intk1,k2,k3,k4,k5,k6,k7,k8,k9,k10;
inti,a,n,s;
for(a=2;a<=