Github 備份:LINK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ C - 701 */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main () | |
{ | |
char string[20]; | |
double output; | |
printf("請輸入一數字的字串: "); | |
scanf("%s", string); | |
output=atof(string); | |
/* atoi()是將字串轉成int格式,atof才是轉成浮點數 */ | |
printf("%s轉換後的浮點數為%f\n", string, output); | |
system("PAUSE"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ C - 702 */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main () | |
{ | |
char string[20]; | |
int output; /* 請宣告成int */ | |
printf("請輸入一數字的字串: "); | |
scanf("%s", string); | |
output=atoi(string); | |
printf("%s轉換後的整數為%d\n", string, output);//顯示的部分,要改成%d | |
system("PAUSE"); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ C - 703 */ | |
#define NTRATE 31.34; | |
/* 符號常數:這行指令表示以NTRATE代替31.34 */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main () | |
{ | |
double USdollar, NTdollar; | |
printf("請輸入您有多少美金: "); | |
scanf("%lf", &USdollar); | |
/* 是要讀入double,所以要用%lf */ | |
NTdollar = USdollar * NTRATE; | |
printf("您可以換%.2f台幣\n", NTdollar); | |
system("PAUSE"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ C - 704 */ | |
#define TRIPLE(x) x*x*x; /* 結尾要有分號 */ | |
/* 定義一個方程式 */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main () | |
{ | |
int num, triple_num; | |
printf("請輸入一個整數: "); | |
scanf("%d", &num); | |
triple_num = TRIPLE(num); | |
printf("%d的三次方為%d\n", num,triple_num); /* 參數少一個num */ | |
triple_num = TRIPLE((4+1)); | |
/* 要清楚它的運作順序,需要先讓4+1處理完,所以我們將它括號起來 */ | |
printf("5的三次方為%d\n", triple_num); | |
system("PAUSE"); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ C - 705 */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main () { | |
enum classify { | |
Freshman, Sophomore, Junior, Senior | |
}; | |
struct student { | |
char *name; | |
enum classify id; | |
}; | |
struct student st1; | |
st1.name="Peter"; | |
st1.id=Junior;//直接用元素當值,然後大三是Junior | |
printf("%s是大三的學生\n", st1.name);//名字要呼叫st1.name | |
system("PAUSE"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ C - 706 */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
int main () | |
{ | |
double x, y; /* 更改為double */ | |
double result; | |
printf("請輸入x, y的值: "); | |
scanf("%lf %lf", &x, &y); /* 因為要讀入double,要用%lf */ | |
result=((exp(5.0)*sqrt((pow(x, y)+log(100.0)))/pow(x, 2))*pow(y, 3)); | |
/* 在這些函式中的參數要用double,exp(double)、pow(double,double)、log(double) */ | |
printf("result=%f\n", result); | |
system("PAUSE"); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ C - 707 */ | |
struct student { | |
char name[20]; | |
int score; | |
}; | |
typedef struct student ST; | |
/* 注意定義的順序 */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
/* 因為我們要使用string的函數 */ | |
int main () | |
{ | |
ST stname; | |
strcpy(stname.name , "Jonh"); /* 將字串複製進去該記憶體 */ | |
stname.score = 90; | |
printf("%s的分數為%d\n", stname.name, stname.score); | |
system("PAUSE"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ C - 708 */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#define random(x) rand()%x+1 | |
/* 亂數要從1~100,所以需要設定成 rand()%x+1 ,rand()%x 為0~99 */ | |
int main() | |
{ | |
int i, j; | |
int x; | |
printf("隨機數的最大值為: "); | |
scanf("%d", &x); | |
for (i=0; i<5; i++) { /* 初始值i=0開始 */ | |
for (j=0; j<4; j++) { /* 初始值j=0開始 */ | |
printf("%5d ", random(x)); | |
} | |
printf("\n"); | |
} | |
system("PAUSE"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
int main () | |
{ | |
double result; | |
double a, b, c, d, e, f; | |
printf("請輸入a, b, c的值: "); | |
scanf("%lf %lf %lf", &a, &b, &c); | |
printf("請輸入d, e, f的值: "); | |
scanf("%lf %lf %lf", &d, &e, &f); | |
result = fabs(a) * floor(b) + pow(c, d) * sqrt(e) + log10(f); | |
printf("result = %f", result); | |
system("PAUSE"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* TQC+ C - 710 */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
/* 若沒有定義Knum, 則加以定義為1000 */ | |
#ifndef Knum | |
#define Knum 1000 | |
#endif | |
/* 將Knum解除定義, 之後再定義為200 */ | |
#undef Knum | |
#define Knum 200 | |
int main () | |
{ | |
/* 印出最後的Knum值 */ | |
printf("Knum = %d\n", Knum); | |
/* 下列的變數d和i共用8個Bytes, 不是12個Bytes */ | |
union dataType { | |
double d; | |
int i; | |
}; | |
union dataType dT; /* 修改dataType的宣告 */ | |
printf("請輸入d的變數值: "); | |
/* 將兩變數分開輸入和顯示 */ | |
scanf("%lf", &dT.d); | |
printf("%lf\n", dT.d); | |
/* 印出dT變數中的d和i */ | |
printf("請輸入i的變數值: "); | |
scanf("%d", &dT.i); | |
printf("%d\n", dT.i); | |
system("PAUSE"); | |
return 0; | |
} |
TQC+ C 試題總覽:LINK
Github 備份:LINK
本篇教學的程式碼皆由筆者編輯,歡迎轉貼本教學,但請全文轉貼,謝啦~
沒有留言:
張貼留言