急!!!两道c++的题

来源:百度知道 编辑:UC知道 时间:2024/07/04 18:22:31
1。编写一程序,实现将一个字符串str1中的小写字母变为大写字母、大写字母保持不变的方式存入另一个字符串str2中,并显示str1 和str2的内容。
2。编写一程序,使之完成下列功能。
要求:完成矩阵转换,输出转换前和转换后的矩阵。
矩阵转换后,计算主对角线数之和,并输出。
1 2 3 4 13 9 5 1
5 6 7 8————》14 10 6 2
9 10 11 12 15 11 7 3
13 14 15 16 16 12 8 4
这样的矩阵,谢谢
1 2 3 4 ---------> 13 9 5 1
5 6 7 8 ---------->14 10 6 2
9 10 11 12---------> 15 11 7 3
13 14 15 16---------> 16 12 8 4

小弟来试试 用c来做
第1题
# include "iostream.h"

void main()
{
char str1[20],str2[20];
cout<<"input the char "<<endl;
cin>>str1;
int i=0;
while(str1[i]!='\0')
{
if(str1[i]>='a'&&str1[i]<='z')
str2[i]=str1[i]-32;
else str2[i]=str1[i];
i++;
}
str2[i]=str1[i];
cout<<str1<<endl;
cout<<str2<<endl;
}

第2题
# include "iostream.h"
# define N 4 //不知道你的矩阵是怎么样的 在这我设它为a[4][4],并给它赋值
void main()
{
int a[N][N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},b[N][N];
int count=0;
cout<<"转换前:"<<endl;
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
cout<<a[i][j]<<'\t';
cout<<endl;
}
cout<<endl;
for(i=0;i<N;i++)