先说两句,开学已经快一个月,今年要冲刺考研,说在寒假把高数,C语言复习一遍,各种原因没坚持下来,一开学就蹲图书馆刷高数,
开始晚上过一下c,然后就准备专业课的复习了,
记录一下。
int i, a[10] = {0,2,3,4,5,6,7,8,};
for (i = 0; i <= 9;i++) {
a[i] = i;
}//给数组赋值
int i, a[5] = { 4,5,6 }, b[5];
printf("\n 数组是:");
for ( i = 0; i < 5; i++)
{
printf("%6d",a[i]);
}
printf("\n数组b是:");
for ( i = 0; i < 5; i++)
{
printf("%6d",b[i]);
}
//获取元素一维数组最大值
int i, max, a[10];
for ( i = 0; i < 10; i++)
{
scanf_s("%d",&a[i]);
}
max = a[0];
for (i = 1; i < 10; i++)
{
if (a[i]>max) {
max = a[i];
}
}
printf(“最大值为:%d\n”, max);
//前二十项斐波那契额数列
int i, a[20];
a[0] = 1;
a[1] = 1;
for (i = 2; i < 20; i++)
{
a[i] = a[i - 1] + a[i - 2];
}
printf(“数组赋值完毕~!”);
//开始遍历哦
for ( i = 0; i < 20; i++)
{
if (0 ==i%5)
{
printf("\n");//每次输出5行
}
printf("\n%12d",a[i]);
}
//冒泡排序,这里没有优化,比如说数列先前就已经排序好,,哎,以后在补充吧。
int i, temp, j;
int a[100] ={ 54,87,65,3,25,32,65,34,55,11 };
//动态给数组赋值
//for ( i = 0; i < 10; i++)
//{
// scanf_s("%d",&a[i]);
//}
//length = sizeof(a);
for ( j = 0; j < 10; j++)
{
for ( i = 0; i < 10; i++)
{
if (a[i] > a[i + 1])
{
temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
}
for ( i = 0; i < 10; i++)
{
printf("\n%d", a[i]);
}
//二维数组,求数组的每列平均值,和每行平均值
int i, j, sum = 0, average, v[3];
int a[5][3] = { {80,75,93},{61,65,71}, {59,63,70},{85,87,90},{76,77,85}};
for ( i = 0; i < 3; i++)
{
for (j = 0; j < 5; j++)
{
sum= sum + a[j][i];
}
v[i] = sum / 5;
sum = 0;
}
average = ((v[0]+v[1]+v[2])/3);
printf(“math:%d\n language:%d\n forxpro:%d\n”,v[0],v[1],v[2]);
printf(“total:%d\n”,average);
//二维数组逆转
int a[2][3] = { {1,2,3}, {4,5,6} };
int b[3][2];
int i, j;
printf(“输出a数组:\n”);
for ( i = 0; i < 2; i++)
{
for (j = 0; j < 3; j++)
{
printf("%5d",a[i][j]);
b[j][i] = a[i][j];//将a[][]元素赋值给b[][]
}
printf("\n");//每行之后要行
}
printf(“输出b数组:%5d\n”);
for ( i = 0; i < 3; i++)
{
for ( j = 0; j < 2; j++)
{
printf("%3d",b[i][j]);
}
printf("\n");
}
/求出二维数组种最大元素的值;
int arry[3][4] = { {1,2,3,5}, {8,9,5,2},{-6,10,-5,2}};
int max = arry[0][0];
int i, j;
int row = 0;//数组的行
int col = 0;//数组的列
//遍历二维数组
for ( i = 0; i <=2; i++)
{
for ( j = 0; j <=3; j++)
{
if (arry[i][j]>max)
{
max = arry[i][j];
row = i;
col = j;
}
}
}//遍历结束
printf("max =%d,row=%d,col = %d\n",max,row,col);//输出数组和对应行列号
内容粗糙,暴力,自己看懂就好,哈哈哈哈