#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int lot[49], choose[7], min = 1, max = 49, num = 7;
int max_dim = max-min+1, choice, i;
for(i=0; i<max_dim; i++){
lot[i] = i+min;
}
srand((unsigned)time(NULL));
for(i=0; i<num; i++){
choice = rand()%max_dim;
choose[i] = lot[choice];
lot[choice] = lot[max_dim-1];
max_dim--;
}
printf("\n 本期大樂透 電腦選號 號碼如下:\n\n");
for(i=0; i<num-1; i++){
printf(" %d", choose[i]);
}
printf("\n\n 特別號: %d \n\n\n", choose[num-1]);
return 0;
}
lifelong learning and ongoing creation
2017年10月8日 星期日
[C] 大樂透開獎
[C] 綜合所得稅試算
/*
說明
請根據綜合所得稅速算公試表,求出使用者輸入綜合所得淨額後,印出稅率、稅金、累進差額還有今年應納稅額。
Input Format
今年所得
Output Format
所得淨額:
稅額:
稅金:
累進差額:
今年應繳:
Sample Input
1230000
Sample Output
income 1230000
tax rate 21%
tax 258300
discount 105100
taxpay 153200
*/
#include <stdio.h>
int main()
{
int income, discount;
double taxrate;
scanf("%d", &income);
if(income>=0 && income<=370000){
taxrate = 0.06;
discount = 0;
}
else if(income>370000 && income<=990000){
taxrate = 0.13;
discount = 25900;
}
else if(income>990000 && income<=1980000){
taxrate = 0.21;
discount = 105100;
}
else if(income>1980000 && income<=3720000){
taxrate = 0.3;
discount = 283300;
}
else if(income>3720000){
taxrate = 0.4;
discount = 655300;
}
else{
printf("input error\n");
}
printf("income %d\n", income);
printf("tax rate %.0f%%\n", taxrate*100);
printf("tax %.0f\n", income*taxrate);
printf("discount %d\n", discount);
printf("taxpay %.0f\n", income*taxrate-discount);
return 0;
}
[C] 猜數字遊戲
/* 說明 猜數字遊戲 讓系統隨機生成一數字介於1到5之間 使用者輸入一數字猜此數字是什麼 猜對的話輸出”猜對了” 猜錯則反之輸出”猜錯了” Input Format 猜的數字1-5 Output Format 猜對的話輸出”你猜對了 答案正是 x” 猜錯則反之輸出”猜錯了了喔 其實是 x” Sample Input 3 Sample Output bingo answer is 3 Sample Input 3 Sample Output wrong answer, answer is 5 */ #include <stdio.h>#include <stdlib.h> #include <time.h> int main() { int guess, keyin; srand((unsigned)time(NULL)); guess = rand()%5+1; scanf("%d", &keyin); if(guess == keyin) printf("bingo answer is %d\n", guess); else printf("wrong answer, answer is %d\n", guess); return 0; }
訂閱:
意見 (Atom)