一.分数的累加
#include <iostream>
using namespace std;
int main ()
{
double sum=0,x=0;int i=1,k=1;
while(i<=19)
{
x=i*1.0/(i+2)*k;
k=-k;
sum+=x;
i=i+2;
}
cout<<"sum="<<sum<<endl;
return 0;
}
二.乘法口诀表
#include<iostream>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=6;i=i+1)
{
for(j=1;j<=i;j=j+1)
{
cout<<j<<"x"<<i<<"="<<i*j<<" ";
}
cout<<endl;
}
return 0;
}
三.百钱百鸡
#include<iostream>
using namespace std;
int main()
{
int a,b;
double c;
for (a=0;a<=20;a++)
for (b=0;b<=33;b++)
for (c=0;c<100;c++)
if (5*a+3*b+c/3==100 && a+b+c==100)
{
cout<<"鸡翁"<<a<<"只, "<<"鸡母"<<b<<"只, "<<"鸡雏"<<c<<"只; "<<endl;
}
return 0;
}