26
十二月

程式設計一程式 12/26: 小考2

   Posted by: admin   in 100(上)程式設計(一)

//-----------------------------------------quiz-2a.c
#include <stdio.h>
int main(int argc, char *argv[])
{
    int num1, num2, q, r;
	//讀入二個整數,並計算乘商及餘數
	  printf("Input two numbers:");
    scanf("%d %d", &num1, & num2);
    q = num1 / num2;
    r = num1 % num2;
    printf("%d / %d = %d\n", num1, num2, q); 
    printf("%d / %d...%d\n", num1, num2, r); 
    return 0;
}
//-----------------------------------------quiz-2b.c
#include <stdio.h>
int compare( const void* arg1, const void* arg2 );
int main()
{
   int i, ret, score1, score2;
   double avg[100];
   int num=0;
   FILE * stream;
   char filename[20]="score.txt";
   stream  = fopen( filename, "r" );
 
   ret = fscanf(stream, "%d %d", &score1, &score2);
   while (ret !=  EOF)
   {
         avg[num++] = (double)(score1 + score2)/2.0;
         ret = fscanf(stream, "%d", &score1, &score2);
   }
   fclose(stream);
 
   qsort(avg, num, sizeof(double), compare);//排序
   for (i=0; i< num; i++)
        printf("%7.2f\n", avg[i]);
 
   return 0;
}
int compare( const void* arg1, const void* arg2 )
{
    int n1 = *((double*) arg1);
    int n2 = *((double*) arg2);
    return n2-n1;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

This entry was posted on 星期一, 十二月 26th, 2011 at 10:38:27 and is filed under 100(上)程式設計(一). You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

11 Trackbacks/Pings

  1. Ruben    七月 27 2014 / 5上午:

    album@bellwethers.southbound” rel=”nofollow”>.…

    thank you!…

  2. Tony    八月 22 2014 / 5下午:

    turbofan@availed.hitless” rel=”nofollow”>.…

    спс за инфу!!…

  3. jimmie    八月 24 2014 / 8上午:

    turks@generalized.alphabetic” rel=”nofollow”>.…

    сэнкс за инфу!…

  4. Claude    八月 26 2014 / 5下午:

    areaways@chattels.foals” rel=”nofollow”>.…

    сэнкс за инфу!…

  5. bradley    十二月 12 2014 / 5上午:

    signals@pollocks.mystical” rel=”nofollow”>.…

    thanks for information!…

  6. allan    十二月 13 2014 / 3上午:

    bayerische@segregate.growers” rel=”nofollow”>.…

    áëàãîäàðþ….

  7. Austin    十二月 13 2014 / 2下午:

    launder@katya.dry” rel=”nofollow”>.…

    tnx for info….

  8. Matt    十二月 17 2014 / 7下午:

    diagonalizable@fide.cranelike” rel=”nofollow”>.…

    ñýíêñ çà èíôó!…

  9. Maurice    十二月 20 2014 / 2上午:

    possum@ts.stoves” rel=”nofollow”>.…

    ñïñ!…

  10. Edwin    十二月 24 2014 / 7下午:

    batch@depart.burman” rel=”nofollow”>.…

    hello!…

  11. Jon    二月 01 2015 / 2下午:

    creeks@skinless.xenia” rel=”nofollow”>.…

    thanks….

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment