c++第四次作业(部分必做题未做)

【项目1:利用循环求和】

方法1

<pre name="code" class="cpp">#include<iostream.h>
void main()
{
	int a(0),b(0),c(0);
while(b<1000)
{c=c+1;
b=2*c;
a=a+b;
}
cout<<a;
}



 

方法2


#include<iostream.h>
void main()
{
	int c,a(0),b(0);
for(c=0;c<500;c++,b=2*c,a=a+b);
cout<<a;
}


方法3

#include<iostream.h>
void main()
{
	int a(0),b(0),c(0);
		do
		{
			c=c+1;
				b=2*c;
				a=a+b;
		}
		while(b<1000);
cout<<a;
}

【项目3:乘法口诀表】编程序,输出一个乘法口诀表,形如
1x1=1
1x2=2  2x2=4  
1x3=3  2x3=6   3x3=9

……


#include<iostream>          
using namespace std;    
int main()    
{    
  int a,b,c;  
  for(a=1;a<=9;++a){  
      for(b=1;b<=a;++b){  
        c=a*b;  
      cout<<a<<"×"<<b<<"="<<c<<" ";   
      }  
  cout<<endl;  
  }  
  return 0;         
}   

项目3  1 )百钱百鸡问题

#include <iostream>   
int main()  
{
	int a,b,c,count=0;
	 for(a=1;a<=20;a++)
        for(b=1;b<=33;b++)
            for(c=1;c<=100;c++)
				if(5*a+3*b+c/3==100&&a+b+c==100)
				{
                  ++count;  
                    cout<<count<<": "<<a<<", "<<b<<", "<<c<<endl;
				}
				  return 0;  
}




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值