第六周作业!

  实验作业

1.调试分析课本每一个例题,有可能的话更改成2-3个方法的新程序;

2.编程实现课本每一个编程习题。

3. 编程定义一个4X5矩阵和5X3矩阵,并计算它们的积。

4.编程输出1到n的平方的自然数构成的“魔方阵”,魔方阵是指它每一行和每一列及对角线之和均相等的方阵。

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

例4.1

// wolugechun.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[10];
	int i;
	for(i=0;i<10;i++)
		a[i]=i*2+2;
	for(i=0;i<10;i++)
	{
	cout<<a[i]<<'\t';             //此处可以省去一个IF语句
	}
	cout<<endl;
	return 0;
}


课后习题1

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

#include "stdafx.h"
#include<iostream>
#include<iomanip>
using namespace std;
int main(int argc, char* argv[])
{
	int a[5],i,big;
	cout<<"请输入五个整数:\n";
		for(i=0;i<5;i++)
			cin>>a[i];
		cout<<"它们是:";
		for(i=0;i<5;i++)
			cout<<setw(4)<<a[i];
		cout<<endl;
		big=a[0];
		for(i=1;i<5;i++)
			if(a[i]>big)
				big=a[i];
			cout<<"其中最大的数是:"<<big<<endl;

	return 0;
}

课后习题2

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

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

int main(int argc, char* argv[])
{
	int a[2][3],i,j;
	cout<<"请输入两行三列维数组的元素值:"<<endl;
	for(i=0;i<2;i++)
		for(j=0;j<3;j++)
		{
			cout<<"a["<<i<<"]["<<j<<"]=";
			cin>>a[i][j];
		}
		cout<<"\n该二维数组为:"<<endl;
		for(i=0;i<2;i++)
		{
			for(j=0;j<3;j++)
				cout<<setw(8)<<a[i][j];
			cout<<endl;
		}
		int row=0,column=0,max=a[0][0];
		for(i=0;i<2;i++)
			for(j=0;j<3;j++)
				if(max<a[i][j])
				{max=a[i][j];row=i;column=j;}
				cout<<"\n该数组中最大的元素值为:"<<"a["<<row<<"]["<<column<<"]="<<a[row][column]<<endl;
	return 0;
}

课后习题5

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

#include "stdafx.h"
#include<iostream>
#include<cstring>
using namespace std;
int main(int argc, char* argv[])
{
	char str[100];
	int len=0;
	cout<<"请输入一个字符串:";
	cin.get(str,100);
	while(str[len]!='\0')
		len++;
		cout<<"字符串"<<str<<"的长度为:"<<len<<endl;
	cout<<"字符串"<<str<<"的反向字符串为:";
	for(int i=strlen(str)-1;i>=0;i--)
		cout<<str[i];
	cout<<endl;
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值