Archive for 十一月 19th, 2009

19
十一月

C程式設計11/12上課: 期中考程式說明

   Posted by: admin    in 98(上)C程式設計

20091119CP

計算所得稅的演算法

計算所得稅的演算法

計算所得稅的程式:input:輸入所得淨額 計算:if()判斷式+稅金計算 output:稅金金額

計算所得稅的程式:input:輸入所得淨額 計算:if()判斷式+稅金計算 output:稅金金額

 

捷運票價計算:示範陣列變數,流程控制(while/for loops)及檔案讀寫

捷運票價計算:示範陣列變數,流程控制(while/for loops)及檔案讀寫

 

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

#include <stdio.h>
 
main()
{
   int ret, i, ss, count, sum, price;
   int distance[100];
   FILE * stream;
   char filename[20]="distance.txt";
   if( (stream  = fopen( filename, "r" )) == NULL )
   {
      printf( "The file %s was not opened\n", filename );
      return -1;
   }
   i=0;
   ret = fscanf(stream, "%d\n", &ss);
   while (ret !=  EOF)
   {
         distance[i++]=ss;
         ret = fscanf(stream, "%d\n", &ss);
   }
   count = i;
   fclose(stream);
 
   sum=0;
   for (i=0; i<count; i++)
   {
   	  sum=sum+distance[i];
   	  price = 20+5*((sum+2)/4);
   	  printf("The price from station 0 to %d is %d\n", i+1, price);
   }
 
   return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: ,

19
十一月

C程式設計11/12範例: 簡化的稅金計算

   Posted by: admin    in 98(上)C程式設計

#include <stdio.h>
main()
{
   int income, tax;
   printf("Please input net income:", income);
   scanf("%d", &income);
   if (income<370000)
      tax = income *6 /100;
   else
      tax = (370000 *6 /100)+(income - 370000)*13/100;
   printf("Income=%d Tax=%d", income, tax);
   return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: ,