c++第4次作业

项目二

#include <iostream>
using namespace std;
int main()
{
	int i=1,k=1;
	double sum=0;
	while(i<=19)
	{
		sum=sum+k*i*1.0/(i+2);
		i=i+2;
		k=k*-1;
	}
	cout<<"本次计算的值为"<<sum<<endl;
	return 0;
}


项目六
#include <iostream>		
using namespace std;	
int main( )
{
	int i,j,n=6; 
	
	for(j=1; j<=n-1; j++)
		cout<<" ";
	cout<<"*"<<endl;
	for(i=2;i<=n-1;i++) 
	{
		for(j=1; j<=n-i; j++) 
			cout<<" ";
		cout<<"*";
		for(j=1; j<=2*i-3; j++) 
			cout<<" ";
		cout<<"*"<<endl; 
	}
	for(j=1; j<=2*n-1; j++) 
		cout<<"*";
	cout<<endl;
	return 0;	
}

项目七

#include<iostream>  
using namespace std;  
int main()  
{  int x,y,z,counter=0;  
         for(x=0; x<=20; x++)  
            for(y=0; y<=33; y++)  
               for(z=0; z<=300; z++)  
         {  
             if( (5*x+3*y+z*1.0/3==100)&&(x+y+z==100) )  
             {  
                    counter++;  

                    cout<<"买法"<<counter<<":"<<"\n鸡翁"<<x<<"只\n鸡母"<<y<<"只\n鸡雏"<<z<<"只"<<endl;  
             }  
         }  
    return 0;  
}  




你可能感兴趣的:(c++第4次作业)