c++作业4

百钱百鸡问题:中国古代数学家张丘建在他的《算经》中提出了著名的“百钱买百鸡问题”:鸡翁一,值钱五,鸡母一,值钱三,鸡雏三,值钱一,百钱买百鸡,问翁、母、雏各几何?

#include<iostream>
using namespace std;
int main()
{
	int x,y,z,count=0;
	cout<<"百钱买百鸡的方案有:"<<endl;
	for(x=0;x<=20;x++)
	{
		for(y=0;y<=33;y++)
		{
		z=100-x-y;
		if(5*x+3*y+z/3==100)
		{
			++count;
				cout<<count<<"公鸡有"<<x<<"只,母鸡有"<<y<<"只,鸡雏有"<<z<<"只"<<endl;


		}
		}
	}
		return 0;
}
	


编程序,输出一个乘法

#include<iostream>
using namespace std;
int main()
{
	int i,j,sum,f=1;
	cout<<"乘法口诀表为"<<endl;
	for(i=1;i<=9;i++)
	{
		for(j=1;j<=i;j++)
		{
			sum=i*j;
			f++;
			cout<<i<<"*"<<j<<"="<<sum<<"\t";
		}
		cout<<endl;
	}
	return 0;
}


输出星号图】编程序输出。

 

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



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值