(1)
main()
{int a[10]={1,2,3,4,5,6,7,8,9,10},b[10],i,j=0;
for(i=0;i<10;i++)
if(a[i]%2)
b[j++]=a[i];
for(i=0;iprintf("%d ",b[i]);
getch();
}
(2)
main()
{int a[11],i,j,m;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for(i=0;i<10;i++)
if(m break;
for(j=9;j>=i;j--)
a[j+1]=a[j];
a[i]=m;
for(i=0;i<11;i++)
printf("%d ",a[i]);
printf("\n");
getch();
}
(3)
main()
{int a[2][2]={{1,2},{3,4}},b[3][3]={{1,2,3},{4,5,6},{7,8,9}},s=0,i,j;
for(i=0;i<2;i++)
for(j=0;j<2;j++)
s+=a[i][j];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
s+=b[i][j];
printf("%d\n",s);
getch();
}
#include "iostream.h"
// 1 奇数
int jishu(int * a,int n,int * &b)
{
int i = 0;
for(int j=0;j
if(a[j] & 1) //奇数
{
b[i++] = a[j];
}
}
return i;
}
//2 插入
//x 待插入 ,c待插入数组,n已有个数
void charu(int x,int* &c,int n)
{
for(int i = 0;i
if(x
}
int temp;
for(int j=i;j<=n;j++)
{
temp = c[j];
c[j] = x;
x = temp;
}
}
main()
{
int a[]= {1,5,7,13,22,48};
int * b = new int[sizeof(a)/sizeof(int)]; //奇数组
int * c = new int[100]; //待插入组
c[0] = a[0];c[1] = a[1];c[2] = a[2];
c[3] = a[3];c[4] = a[4];c[5] = a[5];
cout<<"原数列:";
for(int i = 0;i
// 1
//===================================================
cout<<"\n\n\n奇数测试\n";
int n =jishu(a,sizeof(a)/sizeof(int),b);
for(i = 0;i
// 2
//===================================================
cout<<"\n\n\n插入测试\n";
cout<<"\n插入0,新数列:";
charu(0,c,6);
for(i = 0;i<7;i++)cout<
charu(15,c,7);
for(i = 0;i<8;i++)cout<
charu(100,c,8);
for(i = 0;i<9;i++)cout<
// 3
//===================================================
cout<<"\n\n\n矩阵(以2*5为例)\n";
int x,y;
int juzhen1[][5] = { 1,2,3,4,5,
5,4,3,2,1} ;
int juzhen2[][5] = { 11,12,13,14,15,
51,41,31,21,11} ;
cout<<"矩阵1:\n";
for(x = 0;x<2;x++)
{
for(y =0;y<5;y++)
{
cout <
cout<<'\n';
}
cout<<"矩阵2:\n";
for(x = 0;x<2;x++)
{
for(y =0;y<5;y++)
{
cout <
cout<<'\n';
}
for(x = 0;x<2;x++)
for(y =0;y<5;y++)
{
juzhen1[x][y] += juzhen2[x][y];
}
cout<<"矩阵和:\n";
for(x = 0;x<2;x++)
{
for(y =0;y<5;y++)
{
cout <
cout<<'\n';
}
delete b;
delete c;
}