第四周作业

实验作业

1.完成课本每一个编程题。要求先画出流程算法图或N-S图,然后编程实现,有可能的话使用两种以上方法;

2.编程求“百钱百鸡”问题。(鸡翁一值钱五,鸡母 一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?)

3.编程输入一个整数,计算它是几位数字,分别输出每一位数字,并输出各个数位上数字之和。

4.在一个平面上,有四个圆柱形塔,塔底圆心坐标分别为(2,2)、(-2,2)、(-2,-2)、(2,-2),塔半径为1,塔高为10米,塔外无建筑物。编程,输入任一个点平面坐标,求该点建筑物的高度。

5.编程计算s=1!+2!+3!+......n!(其中n为整数,n!表示计算n阶乘),要求使用两种以上的方法。

6.猴子吃苹果问题:猴子第一天摘了若干个苹果,当时吃了一半,还不过隐,又多吃了一个。第二天,又吃掉余下的一半,又多吃一个。以后每一天,都是吃掉前一天余下的一半零一个。到第10天,只有一个苹果了。问猴子第一天共摘了多少个苹果?

7.计算s[n]=a+aa+aaa+aa...a(n个)的值。其中a是一个数字,n表示a的位数。例如,当a=1,n=5时,则要计算的表达式为

    s[5]=1+11+111+1111+11111

8.打印九九乘法表。

9.两个羽毛队进行单打比赛,各出3个人。甲队为张三、李四、王五3个队员,已队为陈六、赵七、宋八3个队员。现已经抽签决定比赛名单,有人向队员打听比赛名单,张三说他不和陈六打,王五说他不和陈六和宋八打。请编程找出3对比赛名单。

10.积累调试程序经验,收集错误信息原因(每个同学收集3-5条错误信息原因,并输入电脑形成文字)。

 

// 强制显示正号 : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	double x= 66,y= -8.246;
	cout<<"x="<<x<<"\t\t"
		<<"y="<<y<<endl;
	cout<<setiosflags(ios::showpos);     //设置强制显示正号
	cout<<"x="<<x<<"\t\t"
		<<"y="<<y<<endl;
	return 0;
}


课后习题3

// jiesca.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
	int i,j;
	for(i=0;i<5;i++)
	{
		for(j=i;j<5;j++)
			cout<<"*";
		cout<<endl;
	}
	return 0;
}

输出结果为 :


// do-while语句实验程序.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
	int sum,n;
	n=1;
	sum=0;
	do
	{
		sum+=n;
		n++;
	}while(n<=100);
	cout<<"sum="<<sum<<endl;
	return 0;
}

// 乘法表!.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int main(int argc, char* argv[])
{
	int a,b,c;
	for(a=1;a<=9;a++)
	{
		for(b=1;b<=a;b++)
		{
			c=a*b;
			cout<<a<<"*"<<b<<"="<<c<<endl;
		}
			cout<<endl;
	
	}
	return 0;
}


// 计算一个整数的位数以及求各位数之和程序 : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>  
using namespace std;  
int  main()  
{  
    int a,b,c,d=0;  
    cout<<"please input a number"<<endl;  
    cin>>a;  
    for(b=10;b<=a;b*=10)  
    {  
    if(a/b>=1)  
        c=1;  
    d+=c; 
	}
    cout<<"这是一个"<<d+1<<"位数"<<endl;  
      
    d=0;  
    for(b=b/10;b>=1;b=b/10)  
    {  
    c=a/b;  
    d+=c;  
    a%=b;  
    }  
    cout<<"各位数之和等于:"<<d<<endl;  
      
    return 0;  
}

// 百钱百鸡问题.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>  
using namespace std;  
int main()  
{  
    int a,b,c;  
    for(a=0;a*5<=100;a++)  
        for(b=0;(a*5+b*3)<=100;b++)  
        {  
        c=100-a-b; 
        if((a*5+b*3+c/3==100)&&(c%3==0))
            cout<<"公鸡"<<a<<"个"  
            <<"母鸡"<<b<<"个"  
            <<"小鸡"<<c<<"个"<<endl;  
        }  
    return 0;  
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值