例题6-1
![在这里插入图片描述](http://img.e-com-net.com/image/info8/0e401eddeea44e85a432eeb837f83dfd.jpg)
#include
int a[10] = { 0,1,2,3,4,5,6,7,8,9 };
int main(void)
{
for (int i = 1; i <= 10; i++)
{
printf("a[%d]=%d\n", 10 - i, a[10 - i]);
}
return 0;
}
![C程序设计(第五版 谭浩强著)再学习第六章_第1张图片](http://img.e-com-net.com/image/info8/7a491b06def94a549dbaf0ef983962e8.jpg)
例题6-2
![在这里插入图片描述](http://img.e-com-net.com/image/info8/b26e2dd3eb5447c1837c2a09eb38aca1.jpg)
题目回忆
![C程序设计(第五版 谭浩强著)再学习第六章_第2张图片](http://img.e-com-net.com/image/info8/fbcc0b26956f46c78ae5582272ed51a4.jpg)
#include
int a[40] = { 0 };
int main(void)
{
a[0] = 1;
a[1] = 1;
for (int i = 2; i <= 39; i++)
{
a[i] = a[i - 1] + a[i - 2];
}
for (int i = 0; i <= 9; i++)
{
printf("%12d%12d%12d%12d\n", a[4 * i], a[4 * i + 1], a[4 * i + 2], a[4 * i + 3]);
}
return 0;
}
![C程序设计(第五版 谭浩强著)再学习第六章_第3张图片](http://img.e-com-net.com/image/info8/35df020e7acb4f6e886bfb2c1b5449ff.jpg)
例题6-3
![在这里插入图片描述](http://img.e-com-net.com/image/info8/46c4a8382ebf41ddbab1084f37df7be0.jpg)
#include
int area[10] = {10,9,8,7,6,5,4,3,2,1};
int bottle = 0;
int main(void)
{
for (int i = 0; i <= 8; i++)
{
for (int j = 0; j <= 8-i; j++)
{
if (area[j] > area[j + 1])
{
bottle = area[j + 1];
area[j + 1] = area[j];
area[j] = bottle;
}
}
}
for (int i = 0; i <= 9; i++)
printf("area[%d] = %d\n", i, area[i]);
return 0;
}
![C程序设计(第五版 谭浩强著)再学习第六章_第4张图片](http://img.e-com-net.com/image/info8/83fc1557b7bd45eaabacd351ace981c9.jpg)
#include
int area[10] = {34,67,90,43,124,87,65,99,132,26};
int bottle = 0;
int main(void)
{
for (int i = 0; i <= 8; i++)
{
for (int j = 0; j <= 8-i; j++)
{
if (area[j] > area[j + 1])
{
bottle = area[j + 1];
area[j + 1] = area[j];
area[j] = bottle;
}
}
}
for (int i = 0; i <= 9; i++)
printf("area[%d] = %d\n", i, area[i]);
return 0;
}
![C程序设计(第五版 谭浩强著)再学习第六章_第5张图片](http://img.e-com-net.com/image/info8/977f1cbd46044a92ab4853d206250793.jpg)
小知识点:
![C程序设计(第五版 谭浩强著)再学习第六章_第6张图片](http://img.e-com-net.com/image/info8/e188c7b175724d33b88f450d91730fab.jpg)
例题6-4
![C程序设计(第五版 谭浩强著)再学习第六章_第7张图片](http://img.e-com-net.com/image/info8/d2ec00022fab47f7887a3cdbc88872c0.jpg)
#include
int a[2][3] = {{1,2,3},{4,5,6}};
int b[3][2] = { 0 };
int i = 0, j = 0;
int main(void)
{
printf("array a:\n");
for (i = 0; i <= 1; i++)
{
for (j = 0; j <= 2; j++)
printf("%d\t", a[i][j]);
printf("\n");
}
printf("array b:\n");
for (i = 0; i <= 2; i++)
{
for (j = 0; j <= 1; j++)
{
b[i][j] = a[j][i];
printf("%d\t", b[i][j]);
}
printf("\n");
}
return 0;
}
![C程序设计(第五版 谭浩强著)再学习第六章_第8张图片](http://img.e-com-net.com/image/info8/47d1ebbb1c624b42b2a75623191e98ce.jpg)
例题6-5
![在这里插入图片描述](http://img.e-com-net.com/image/info8/d4f5fdb31edb486ab1aaca52a8529a9d.jpg)
![C程序设计(第五版 谭浩强著)再学习第六章_第9张图片](http://img.e-com-net.com/image/info8/b413a1f03d154e83947ffdd0578c0130.png)