C++第四次作业

<p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; line-height: 35px;"><span style="font-size:12px;">一、<span style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;">求1000以内所有偶数的和</span></span></p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; line-height: 35px;"><span style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px;"><span style="font-size:12px;">1、whlie语句</span></span></p>
#include <iostream>   
using namespace std;  
int main()  
{  
  int i(0),sum(0);
  while (i<=1000)
  {
	  sum+=i;
	  i=(i+2);
  }
  cout<<"sum="<<sum<<endl;
    return 0;  
}
2、do while 语句
#include <iostream>   
using namespace std;  
int main()  
{  
   int i(0),sum(0);
   do
   {
	   sum+=i;
	   i=i+2;
   }while(i<=1000);
   cout<<"sum="<<sum<<endl;
    return 0;  
}
3、for语句
#include <iostream>   
using namespace std;  
int main()  
{  
	int i,sum;
	sum=0;
   for(i=0;i<=1000;i=i+2)
	   sum=sum+i;
   cout<<"sum="<<sum<<endl;
    return 0;  
}

二、乘法口诀表

<span style="font-family:SimHei;font-size:12px;">#include<iostream>  
using namespace std;  
int main()  
{  
    int i,j,k;  
    for(i=1;i<10;i++)  
    {  
        for(j=1;j<=i;j++)  
        {  
            k=i*j;  
            cout<<j<<"*"<<i<<"="<<k<<"\t";  
        }  
        cout<<endl;  
    }  
    return 0;  
}  </span>

3、输出星号图

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值