Archive for the ‘程式設計一(99)’ Category

8
一月

程式設計01/07程式:程式(quiz-2a.c)

   Posted by: admin Tags: , ,

#include <stdio.h>
void NumGen(int List[]);
int main()
{
   int mumbers[3];
   NumGen(mumbers);
   printf("The numbers: %d %d %d.", mumbers[0], mumbers[1], mumbers[2]);
 
 
   if (mumbers[0]>=mumbers[1] && mumbers[0]>=mumbers[2]) //比較最大的數 
      printf("The biggest is %d\n", mumbers[0]);
   else if (mumbers[1]>=mumbers[2])
      printf("The biggest is %d\n", mumbers[1]);
   else
      printf("The biggest is %d\n", mumbers[2]);
   return 0;
}
void NumGen(int List[])
{
    int i, j;
    int ball[10];
    int biggest, which;
 
    for (i=0; i< 10; i++)
    {
        ball[i] = rand();
    }
    for (i=0; i<3; i++)
    {
        biggest = -1;
        for (j=0; j <10; j++)
        {
            if (ball[j] > biggest)
            {
               biggest = ball[j];
               which = j;
            }
        }
        ball[which] = -1;
        List[i]= which + 1;
    }
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

8
一月

程式設計01/07程式:程式(quiz-2b.c)

   Posted by: admin Tags: , ,

#include <stdio.h>
int compare( const void* arg1, const void* arg2 );
int main()
{
   int i, ret, score;
   int arr[100], num=0;
   FILE * stream;
   char filename[20]="score.txt";
   stream  = fopen( filename, "r" );
 
   ret = fscanf(stream, "%d", &score);
   while (ret !=  EOF)
   {
         arr[num++] = score;
         ret = fscanf(stream, "%d", &score);
   }
   fclose(stream);
 
   qsort(arr, num, sizeof(int), compare);//排序
   for (i=0; i< num; i++)
        printf("%d ", arr[i]);
 
   return 0;
}
int compare( const void* arg1, const void* arg2 )
{
    int n1 = *((int*) arg1);
    int n2 = *((int*) arg2);
    return n2-n1;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

8
一月

程式設計01/07程式:程式(fin-1b.c)

   Posted by: admin Tags: , ,

#include <stdio.h>
int compare( const void* arg1, const void* arg2 );
int main()
{
   int i, ret, score;
   int arr[100], adj[100], num=0;
   FILE * stream;
   char filename[20]="score.txt";
   stream  = fopen( filename, "r" );
 
   ret = fscanf(stream, "%d", &score);
   while (ret !=  EOF)
   {
         arr[num] = score;
         if (score >=60)
            adj[num] = score * 8 /10 + 20;
         else
            adj[num] = score * 7 /10 + 30;
         num++;
         ret = fscanf(stream, "%d", &score);
   }
   fclose(stream);
   qsort(arr, num, sizeof(int), compare);//排序
   qsort(adj, num, sizeof(int), compare);//排序
   printf("Before adjust:");
   for (i=0; i< num; i++)
        printf("%d ", arr[i]);   
   printf("\nAfter  adjust:");
   for (i=0; i< num; i++)
        printf("%d ", adj[i]);
 
   return 0;
}
int compare( const void* arg1, const void* arg2 )
{
    int n1 = *((int*) arg1);
    int n2 = *((int*) arg2);
    return n2-n1;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

8
一月

程式設計01/07程式:程式(fin-1a.c)

   Posted by: admin Tags: , ,

#include <stdio.h>
int main(int argc, char *argv[])
{
    int num1, num2, num3, mul, sum;
	//讀入三個整數,並計算乘積以及和的平方 
    num1 = atoi(argv[1]);
    num2 = atoi(argv[2]);
    num3 = atoi(argv[3]);
    mul = num1 * num2 * num3 ;
	sum = num1 + num2 + num3;
 
    printf("%d x %d x %d = %d\n", num1, num2, num3, mul); 
    printf("(%d + %d + %d)^2 = %d\n", num1, num2, num3, sum*sum); 
    return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

20101224P2

使用不同程式語言開發的差異: 以Eclipse開發Java程式

使用不同程式語言開發的差異: 以Eclipse開發Java程式

C版本的樂透號碼產生程式

C版本的樂透號碼產生程式

Java版本的樂透號碼產生程式差異

Java版本的樂透號碼產生程式差異

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark