Archive for 八月, 2015

10
八月

暑修資料結構 程式 08/10: ex2.c

   Posted by: admin    in 104(暑)資料結構

#include <stdio.h>
int main()
{
    int iData[10]={12, 5, 7, 16, 13, 19, 6, 18, 4, 11};
    int i,j, tt;
    for (i=0; i<10; i++)
       printf("%2d ", iData[i]);
    printf("\n");
    for (i=9; i>0; i--)
    {
        for (j=1; j <=i; j++)
        {
            if (iData[j-1] > iData[j])
            {
                tt = iData[j-1];
                iData[j-1] = iData[j];
                iData[j] = tt;
            }
        }
        for (j=0; j<10; j++)
             printf("%2d ", iData[j]);
        printf("\n");
    }
 
    return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

10
八月

暑修資料結構 程式 08/4: ex1.c

   Posted by: admin    in 104(暑)資料結構

#include <stdio.h>
int main()
{
	int x, y;
	int s[10][10];
	for (x=1; x <=9; x++)
	{
		for (y=1; y <=9; y++)
		{
			s[x][y]= x*y;
			printf("%2d x %2d = %2d\n", x, y, s[x][y]);
		}		
	}
	return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,