c++第四次作业

时间:2022-02-03 21:58:43
#include <iostream>
using namespace std;
int main()
{
  int a=1,b=1;
  double sum=0;
  while(a<=19)
  {
	sum=sum+b*1.0*a/(a+2);
	a=a+2;
	b=-b;
  }
  cout<<"结果为"<<sum<<endl;
  return 0;
}

#include <iostream>
using namespace std;
int main()
{
int x,y,z;
for(x=0;x<=20;x++)
for(y=0;y<=33;y++)
for(z=0;z<=300;z=z+3)
if(5*x+3*y+z/3==100&&x+y+z==100)
{
cout<<"鸡翁"<<x<<"鸡母"<<y<<"鸡雏"<<z<<endl;
}
return 0;
}

#include <iostream> 
using namespace std; 
int main( )
{
 int a,b,n=6;
 for(a=1,b=1; b<=5;b++) 
 cout<<" ";
 cout<<"*"<<endl;
 for(a=2;a<=5;a++) 
 {
  for(b=1;b<=6-a;b++)
  cout<<" ";
  cout<<"*"; 
  for(b=1; b<=2*a-3;b++) 
  cout<<" ";
  cout<<"*"<<endl; 
 }
 if(a==6)
 cout<<"***********";
 cout<<endl;
 return 0;  
}