C語言建立索引:
#include <stdio.h>
void main(void)
{
int i, j;
int a[5] = {5, 4, 2, 3, 1};
int b[5] = {0, 1, 2, 3, 4}; //下標序號,數量多就自增賦值
int c , d;
printf("原陣列:\n");
for(i = 0; i < 5; i++)
printf("%2d", a[i]);
}
for(j = 4 - i; j < 4; j++)
if(a[j] > a[j+1])//從小到大 冒泡法 交換大小 同時交換下角標
c = a[j];
a[j] = a[j+1];
a[j+1] = c;
d = b[j];
b[j] = b[j+1];
b[j+1] = d;
printf("\n陣列:\n");
printf("\n下標:\n");
printf("%2d", b[i]);
getchar();
C語言建立索引:
#include <stdio.h>
void main(void)
{
int i, j;
int a[5] = {5, 4, 2, 3, 1};
int b[5] = {0, 1, 2, 3, 4}; //下標序號,數量多就自增賦值
int c , d;
printf("原陣列:\n");
for(i = 0; i < 5; i++)
{
printf("%2d", a[i]);
}
for(i = 0; i < 5; i++)
{
for(j = 4 - i; j < 4; j++)
{
if(a[j] > a[j+1])//從小到大 冒泡法 交換大小 同時交換下角標
{
c = a[j];
a[j] = a[j+1];
a[j+1] = c;
d = b[j];
b[j] = b[j+1];
b[j+1] = d;
}
}
}
printf("\n陣列:\n");
for(i = 0; i < 5; i++)
{
printf("%2d", a[i]);
}
printf("\n下標:\n");
for(i = 0; i < 5; i++)
{
printf("%2d", b[i]);
}
getchar();
}