C++作业4

(1)项目三:乘法口诀表

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

(2)项目四:输出完数

#include<iostream>
using namespace std;
int main()
{
	int i,j,k;
	cout<<"1000以内的所有完数有:";
	for(i=2;i<=1000;i++)
	{
		k=0;
		for(j=1;j<=i/2;j++)
			if(i%j==0) k=k+j;
		if(k==i) cout<<k<<",";
	}
	cout<<endl;
	return 0;
}


(3)项目六:输出星号图

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


你可能感兴趣的:(C++作业4)