}
2.
#include
main()
{
intyear,month,days;
cout<<"请输入年份,月份:
";
cin>>year>>month;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
days=31;
cout<}elseif(month==4||month==6||month==9||month==11){
days=30;
cout<}elseif((year%4==0&&year%100!
=0)||year%400==0){
days=29;
cout<}else{
days=28;
cout<}
return0;
}
3.
//收过桥费
#include
main()
{
intkind;
cout<<"1.自行车\n";
cout<<"2.摩托车\n";
cout<<"3.小汽车\n";
cout<<"4.大货车或客车\n";
cout<<"5.货柜车\n";
cout<<"请输入汽车种类:
";
cin>>kind;
switch(kind){
case1:
cout<<"thefeeis:
0yuanonce."<case2:
cout<<"thefeeis:
2yuanonce."<case3:
cout<<"thefeeis:
5yuanonce."<case4:
cout<<"thefeeis:
8yuanonce."<case5:
cout<<"thefeeis:
12yuanonce."<default:
cout<<"Error!
"<}
}
4.
#include
main()
{
intmarks;
cout<<"输入考试成绩:
";
cin>>marks;
switch(marks/10){
case10:
case9:
cout<<"Excellent\n";break;
case8:
cout<<"VeryGood\n";break;
case7:
cout<<"Good\n";break;
case6:
cout<<"Pass\n";break;
default:
cout<<"NoPass\n";
}
return0;
}
5.
//旅行社折扣
#include
main()
{
intnum,price;
floatdiscount,total_price;
cout<<"输入购买张数和单价:
";
cin>>num>>price;
switch(num/10){
case0:
discount=0.1;break;
case1:
discount=0.15;break;
default:
discount=0.3;
}
total_price=num*price*(1-discount);
cout<<"总价格为:
"<return0;
}
6.
//输入数流
#include
main()
{
inta[100],i,j,x=0,y=0,z=0;
cout<<"输入数流(以1000结束):
";
for(i=0;;i++){
cin>>a[i];
if(a[i]==1000)break;
}
for(j=0;a[j]!
=1000;j++){
if(a[j]==-1)x++;
if(a[j]==0)y++;
if(a[j]==1)z++;
}
cout<<"该数流中含-1:
"<cout<<"该数流中含0:
"<cout<<"该数流中含1:
"<return0;
}
7.
//求2因子
#include
main()
{
intx,i,n;
cout<<"输入整数:
";
l:
cin>>x;
if(x<0){
cout<<"输入有误!
请重新输入:
";
gotol;
}
n=x;
for(i=0;n%2==0;i++){
n/=2;
}
cout<<"整数"<return0;
}
8.
#include
main()
{
inti,n;
for(i=7;!
(i%2==1&&i%3==2&&i%4==3&&i%5==4&&i%6==5);i+=7){
n=i;
}
cout<<"最小可能值是:
"<return0;
}
9.
//百元买百鸡
#include
main()
{
intcock,hen,chicken,price;
for(cock=0;cock<=20;cock++){
for(hen=0;hen<=33;hen++){
chicken=100-cock-hen;
if(chicken%3==0&&5*cock+3*hen+chicken/3==100)
cout<<"符合条件的有公鸡"<}
}
return0;
}
10.
#include
main()
{
intmoney,i,m,n;
for(i=1;;i++){
if(4+4*i==5*i-5){
cout<<"money="<<4+4*i<<""<<"price="<
break;
}
elsecontinue;
}
return0;
}
11.
#include
main()
{
intn,i,j,s=0;
for(i=1;i<=100;i++){
if(i%13==0)s+=i;
elsecontinue;
}
cout<<"100以内可以被13整除的自然数之和为:
"<
return0;
}
12.
//求m到n的素数
#include
#include
intf(intn)
{
inta,x,i,b;
x=sqrt(n);
if(n==2||n==3)b=1;
elsefor(i=2;i<=x;i++){
if(n%i==0){
b=0;
break;
}
elseif(i==x)b=1;
elsecontinue;
}
returnb;
}
main()
{
intm,n,x,i,j;
staticintk=0;
l:
cout<<"输入m,n(其中10";
cin>>m>>n;
if(m<=10||m>=n||n>32000){
cout<<"输入数据有误!
请再";
gotol;
}
for(i=m;i<=n;i++){
if(f(i)){
cout<
k++;
if(k%8==0)cout<}
}
cout<return0;
}
13.
//打印乘法口诀表
#include
main()
{
inti,j;
for(i=1;i<=9;i++){
for(j=1;j<=i;j++)cout<
cout<}
return0;
}
14.
//求最大公约数
#include
main()
{
intm,n,temp;
cout<<"输入两个整数:
";
cin>>m>>n;
temp=mm:
n;
m=mn:
m;
n=temp;
for(;;){
temp=m%n;
if(temp){
m=n;
n=temp;
}
else{
cout<<"最大公约数是:
"<break;
}
}
return0;
}
15.
//求不超过正整数n的2的最大幂值
#include
#include
main()
{
intn,i;
cout<<"请输入正整数n:
";
cin>>n;
for(i=0;pow(2,i)<=n;i++){}
cout<<"满足条件的值为:
"<return0;
}
16.
#include
#include
voidmain()
{
constdoublefishnum=800000000;
doublefnum=fishnum;
intn=1;
while(fnum>=fishnum/2){
fnum=fnum*(1-0.035);
n++;
}
cout<<"当鱼的数目等于原来的一半时,需要"<n=1;
fnum=fishnum;
while(fnum>=fishnum/10){
fnum=fnum*(1-0.035);
n++;
}
cout<<"当鱼的数目等于原来的十分之一时,需要"<}
17.
//二次方程求解
#include
#include
main()
{
floata,b,c;
cout<<"请输入a,b,c:
";
cin>>a>>b>>c;
floatt=b*b-4*a*c;
if(a==0)if(b==0)if(c==0)cout<<"方程根为一切实数"<elsecout<<"方程无根"<elsecout<<"根是:
"<<-c/b<elseif(t>0)cout<<"根x1="<<(-b+sqrt(b))/(-2*a)<elseif(t==0)cout<<"根x1=x2="<<(-b+sqrt(b))/(-2*a)<elsecout<<"根x1="<<(-b)/(-2*a)<<"+"<<"("<<(sqrt(-t))/(-2*a)<<")i"<return0;
}
18.
//班级分数
#include
main()
{
inta[100],i,j,max,min,s=0;
cout<<"输入同学成绩(以1000结束):
";
for(i=0;;i++){
cin>>a[i];
if(a[i]==1000)break;
if(i==0){
max=a[0];
min=a[0];
}
max=max>a[i]?
max:
a[i];
min=minmin:
a[i];
s+=a[i];
}
cout<<"该班同学成绩中最高分为:
"<return0;
}
19.
//模拟四则运算
#include
main()
{
inta,b;
charx;
cout<<"请输入算式:
"<cin>>a>>x>>b;
if(x=='+')cout<<"="<elseif(x=='-')cout<<"="<elseif(x=='*')cout<<"="<elseif(x=='/')cout<<"="<<(float)a/b<elsecout<<"error!
!
!
"<return0;
}
20.
//兑钱
#include
main()
{
inti,j,k,m=0;
for(i=1;i<=20;i++){
for(j=1;j<=50;j++){
k=100-5*i-2*j;
if(k>=1){
m+=1;
//cout<<"i="<
}
}
}
cout<<"共有"<return0;
}
21.
//求e
#include
#include
main()
{
inti;
doubletemp=1,sum=0;
for(i=1;temp>=1e-8;i++){
sum+=temp;
temp/=i;
}
cout<<"e=1+1/1!
+1/2!
+1/3!
+....="<}
22.
//求1!
+2!
~~+7!
#include
intf(intx)
{
intr;
if(x==0)r=1;
elser=x*f(x-1);
returnr;
}
main()
{
inti,s=0;
for(i=1;i<=7;i++){
s+=f(i);
}
cout<<"结果是:
"<
return0;
}
23.
//求1×2+3×4+5×6+…+39×40
#include
main()
{
inti,s=0;
for(i=1;i<=39;i+=2){
s+=i*(i+1);
}
cout<<"结果是:
"<
return0;
}
24.
//求值,精确到10e-6
#include
#include
main()
{
inti,x;
cout<<"输入整数x:
";
cin>>x;
doubletemp=x,s=0;
for(i=1;fabs(temp)>=1e-6;i+=2){
s+=temp;
temp=temp*(-x*x)/((float)(i+1)*(i+2));
}
cout<<"结果是:
"<
return0;
}
25.
//反向输出
#include
#include
main()
{
intx,i,j;
cout<<"输入整数x:
";
cin>>x;
for(i=0;;i++)if(x/(int)pow(10,i)==0)break;
inta[100];
for(j=0;j
a[j]=(x%(int)pow(10,j+1))/((int)pow(1