项目一求1000以内所有偶数的和
#include<iostream.h>
void main()
{
int i(2),sum(0);
while(i<=1000)
{
sum+=i;
i=i+2;
}
cout<<"sum="<<sum<<endl;
}
#include<iostream.h>
void main()
{
int i(2),sum(0);
do
{
sum+=i;
i=i+2;
}while(i<=1000);
cout<<"sum="<<sum<<endl;
}
#include<iostream.h>
int main()
{
int i=0,sum=0;
do
{
i++;
if(i%2==0)
sum+=i;
}
while(i<1001);
cout<<sum;
return 0;
}
【项目3:乘法口诀表】编程序,输出一个乘法口诀表,形如
1x1=1
1x2=2 2x2=4
1x3=3 2x3=6 3x3=9
# include <iostream.h>
int main()
{
int i, k, l = 1;
for(k = 1; k < 10; k++)
{
for(i = 1; i <= k; i++)
{
cout << i << "x" << k << "=" << i*k << " ";
}
l++;
cout << endl;
}
return 0;
}
【项目
6
:输出星号图】编程序输出。
#include <iostream>
using namespace std;
int main()
{
int i,j,n;
cout<<"请输入行数n:"<<endl;
cin>>n;
for(i=1;i<n;i++)
{
cout<<" ";
}
cout<<"*"<<endl;
for(i=2;i<n;i++)
{
for(j=0;j<n-i;j++)
{
cout<<" ";
}
cout<<"*";
for(j=0;j<2*(i-1)-1;j++)
{
cout<<" ";
}
cout<<"*"<<endl;
}
for(j=0;j<=2*i-2;j++)
{
cout<<"*";
}
cout<<endl;
return 0;
}