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 - 801_1 */ | |
#include<stdio.h> | |
#include<stdlib.h> | |
int main () | |
{ | |
int i,j; | |
for(i=1;i<=5;i++){ | |
/* 控制行數 */ | |
for(j=0;j<i;j++) { | |
/* 控制幾顆星 */ | |
printf("*"); | |
} | |
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
/* TQC+ C - 801_2 */ | |
#include<stdio.h> | |
#include<stdlib.h> | |
int main () | |
{ | |
int i,j=5, k; | |
for(i=1;i<=5;i++){ | |
/* 控制行數 */ | |
for(k=j;k>0;k--){ | |
/* 控制幾顆星 */ | |
printf("*"); | |
} | |
j--; | |
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
/* TQC+ C - 801_3 */ | |
#include<stdio.h> | |
#include<stdlib.h> | |
int main () | |
{ | |
int i,j; | |
for(i=1;i<=5;i++){ | |
/* 控制行數 */ | |
int sp=5-i; /* 一行內的空白和星號數量是互補的 */ | |
for(;sp>0;sp--) /* 控制空白數 */ | |
printf(" "); | |
for(j=0;j<i;j++) /* 控制星號數 */ | |
printf("*"); | |
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
/* TQC+ C - 801_4 */ | |
#include<stdio.h> | |
#include<stdlib.h> | |
/* 這題解法僅跟上一題有些差異而已, | |
* 把星號跟空白的寫法稍微對換即可 | |
*/ | |
int main () | |
{ | |
int i,j; | |
for(i=0;i<=5;i++){ | |
/* 控制行數 */ | |
int sp=5-i; /* 一行內的空白和星號數量是互補的 */ | |
for(j=0;j<i;j++) /* 控制空白數 */ | |
printf(" "); | |
for(;sp>0;sp--) /* 控制星號數 */ | |
printf("*"); | |
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
/* TQC+ C - 802 */ | |
#include<stdio.h> | |
#include<stdlib.h> | |
int main(){ | |
int choice; | |
printf("(1)教授\n(2)副教授\n(3)助理教授\n(4)都不是\n(5)結束\n請輸入您的職稱代號:"); | |
scanf ("%d",&choice); | |
while(choice!=5){ | |
/* 只要使用者沒有輸入到5,都會持續去詢問 */ | |
switch (choice){ | |
/* 注意switch case的使用方法 */ | |
case 1: printf("\n您的職稱是教授\n");break; | |
case 2: printf("\n您的職稱是副教授\n");break; | |
case 3: printf("\n您的職稱是助理教授\n");break; | |
case 4: printf("\n您的職稱沒有在這些選項內\n");break; | |
case 5: break; | |
} | |
printf("\n(1)教授\n(2)副教授\n(3)助理教授\n(4)都不是\n(5)結束\n請輸入您的職稱代號:"); | |
scanf ("%d",&choice); | |
} | |
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 - 803 */ | |
#include<stdio.h> | |
#include<stdlib.h> | |
int main(){ | |
int i=0,a=0,b=0,c=0; | |
int ch; | |
while(i<10){/* 總共有10票 */ | |
printf("(1)小蔡\n(2)小王\n(3)小史\n請你投票:"); | |
scanf("%d",&ch); | |
if(ch==1) | |
a++; | |
else if(ch==2) | |
b++; | |
else if(ch==3) | |
c++; | |
else;/* 輸入1~3以外的數字,我們便把它當成廢票 */ | |
printf("\n小蔡得票數%d\n小王得票數%d\n小史得票數%d\n\n",a,b,c); | |
i++; | |
} | |
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 - 804 */ | |
#include<stdlib.h> | |
#include<stdio.h> | |
double average(double* ,int ); | |
int main(){ | |
int i; | |
double cc[6],ans; | |
for(i =0;i<6;i++){ | |
printf("請輸入第%d個浮點數:",(i+1)); | |
scanf("%lf",&cc[i]); | |
} | |
printf("\n您輸入的陣列值如下"); | |
for(i =0;i<6;i++) | |
printf("\ndata[%d]:%.2f",i,cc[i]); | |
ans = average(cc,6); | |
printf("\n平均:%.2f",ans); | |
system("PAUSE"); | |
return 0; | |
} | |
double average(double* arr2,int n){ /* 陣列傳參數方式,使用指標 */ | |
double total=0; | |
int i ; | |
for(i=0;i<n;i++ ) | |
total+=*(arr2+i); /* 注意指標呼叫指標內的值 */ | |
total/=n; | |
return total; | |
} |
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 - 805_1 */ | |
#include<stdlib.h> | |
#include<stdio.h> | |
int main(){ | |
int arr[3][4]; | |
int i,j,tot=0; | |
for(i=0;i<3;i++){ /* 控制列 */ | |
printf("請輸入四個數字(數字之間請以空白為間隔):"); | |
for(j=0;j<4;j++){ /* 控制行 */ | |
scanf("%d",&arr[i][j]); | |
tot+=arr[i][j]; | |
} | |
printf("\n"); | |
} | |
for(i=0;i<3;i++){ | |
for(j=0;j<4;j++){ | |
printf("%d ",arr[i][j]); | |
} | |
printf("\n"); | |
} | |
printf("sum:%d\n",tot); | |
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 - 805_2 */ | |
#include<stdlib.h> | |
#include<stdio.h> | |
int main(){ | |
int arr[5][2]; | |
int i,j,tot=0; | |
for(i=0;i<5;i++){ /* 控制列 */ | |
printf("請輸入兩個數字(數字之間請以空白為間隔):"); | |
for(j=0;j<2;j++){ /* 控制行 */ | |
scanf("%d",&arr[i][j]); | |
tot+=arr[i][j]; | |
} | |
printf("\n"); | |
} | |
for(i=0;i<5;i++){ | |
for(j=0;j<2;j++){ | |
printf("%d ",arr[i][j]); | |
} | |
printf("\n"); | |
} | |
printf("sum:%d\n",tot); | |
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 - 806 */ | |
#include<stdlib.h> | |
#include<stdio.h> | |
void multiply(int); | |
void printStar(int); | |
int main(){ | |
int m,s; | |
printf("請輸入您要幾成己的乘法表(最多10):"); | |
scanf("%d",&m); | |
printf("\n請輸入您要幾個星星(*):"); | |
scanf("%d",&s); | |
printStar(s); | |
if(m<=10) /* 要控制好,10以下(含)才顯示 */ | |
multiply(m); | |
printStar(s); | |
system("PAUSE"); | |
return 0; | |
} | |
void multiply(int n){ /* 乘法函數 */ | |
int i,j; | |
for(i=1;i<=n;i++){ | |
for(j=1;j<=n;j++) | |
printf("%d* %d=%2d ",i,j,(i*j)); | |
printf("\n"); | |
} | |
} | |
void printStar(int n) /*星號列印函數 */ | |
{ | |
int i; | |
for(i=0;i<n;i++) | |
printf("*"); | |
printf("\n"); | |
} |
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 - 807 */ | |
#include<stdlib.h> | |
#include<stdio.h> | |
void multiply(int); | |
void printStar(int); | |
int main(){ | |
int m,s; | |
printf("請輸入您要幾成己的乘法表(最多10):"); | |
scanf("%d",&m); | |
printf("\n請輸入您要幾個星星(*):"); | |
scanf("%d",&s); | |
printStar(s); | |
if(m<=10) | |
multiply(m); | |
printStar(s); | |
system("PAUSE"); | |
return 0; | |
} | |
void multiply(int n){ | |
int i,j; | |
for(i=1;i<=n;i++){ | |
for(j=1;j<=n;j++) | |
printf("%2d ",(i*j));//這題緊跟上一題差別在顯示而已 | |
printf("\n"); | |
} | |
} | |
void printStar(int n) | |
{ | |
int i; | |
for(i=0;i<n;i++) | |
printf("*"); | |
printf("\n"); | |
} |
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 - 807 */ | |
#include<stdlib.h> | |
#include<stdio.h> | |
void sorting(int*, int); | |
int main(){ | |
int scoredata[10]; | |
int i; | |
printf("請輸入十個數...\n"); | |
for(i=0;i<10;i++){ | |
printf("第 %d 個: ",(i+1)); | |
scanf("%d",&scoredata[i]); | |
} | |
printf("排序前:"); | |
for(i=0;i<10;i++) | |
printf(" %d",scoredata[i]); | |
sorting(scoredata,10); | |
/* 因為是傳指標過去,直接操作記憶體中的資料 */ | |
printf("\n排序後:"); | |
for(i=0;i<10;i++) | |
printf(" %d",scoredata[i]); | |
system("PAUSE"); | |
return 0; | |
} | |
void sorting(int* data2,int n){/* 這題著重於此 */ | |
int i,j,LN=n-1; | |
for(i=0;i<LN;i++){ | |
for(j = 0;j<LN;j++){ | |
if(data2[j]>data2[j+1]){ | |
/* 如果前面那個值,大於後面的值,則交換 */ | |
int temp = data2[j+1]; | |
data2[j+1] = data2[j]; | |
data2[j] = temp; | |
} | |
} | |
} | |
/* 由上面的程式碼可得知該演算法時間複雜度為 n 平方 */ | |
} |
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 - 809 */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
void sort(int*,int); | |
int main(){ | |
int arr[15]; | |
int arr2[5][3]; | |
int n = 15,i,j,number=0; | |
printf("請輸入...\n"); | |
for(i=0;i<n;i++){ | |
printf("arr[%d]: ",i); | |
scanf("%d",&arr[i]); | |
} | |
sort(arr,n); | |
for(i=0;i<5;i++){ | |
for(j=0;j<3;j++){ | |
arr2[i][j] = arr[number]; | |
number++; | |
} | |
} | |
printf("印出陣列..."); | |
for(i=0;i<5;i++){ | |
for(j=0;j<3;j++){ | |
printf("\narr2[%d][%d]=%d",i,j,arr2[i][j]); | |
} | |
} | |
system("PAUSE"); | |
return 0; | |
} | |
void sort(int *data,int n){ | |
int i ,j,min,temp; | |
for(i=0;i<n;i++){ | |
min =i; | |
for(j=(i+1);j<n;j++){ | |
if(data[j]<data[min]){ | |
min =j ; | |
temp =data[i]; | |
data[i]=data[min]; | |
data[min]=temp; | |
} | |
} | |
} | |
} |
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 - 810 */ | |
#include<stdlib.h> | |
#include<stdio.h> | |
void m(int*, int*, int*); | |
void printbox(int,int,int*); | |
int main(){ | |
int arr1[3][3]; | |
int arr2[3][3]; | |
int ans[3][3]; | |
int i,j; | |
printf("請輸入矩陣一...\n"); | |
for(i=0;i<3;i++){ | |
for(j=0;j<3;j++){ | |
printf("m1[%d][%d]:",i,j); | |
scanf("%d",&arr1[i][j]); | |
} | |
} | |
printf("請輸入矩陣二...\n"); | |
for(i=0;i<3;i++){ | |
for(j=0;j<3;j++){ | |
printf("m2[%d][%d]:",i,j); | |
scanf("%d",&arr2[i][j]); | |
} | |
} | |
printf("\n矩陣一\n"); | |
printbox(3,3,arr1[0]); | |
printf("\n矩陣二\n"); | |
printbox(3,3,arr2[0]); | |
printf("\n矩陣三\n"); | |
m(arr1[0],arr2[0],ans[0]); | |
printbox(3,3,ans[0]); | |
system("PAUSE"); | |
return 0; | |
} | |
void m(int* a1,int* a2,int* ans){ | |
int i,j; | |
for(j=0;j<(3*3);j++){ | |
*(ans+j) = *(a1+j)*(*(a2+j)); | |
} | |
} | |
void printbox(int x,int y,int* d){ /* x行y列 */ | |
int i,j; | |
int c=0; | |
for(i=0;i<(x*y) ;i++){ | |
printf(" %2d",*(d+i)); | |
c++; | |
if(c==y){ | |
printf("\n"); | |
c=0; | |
} | |
} | |
} |
TQC+ C 試題總覽:LINK
Github 備份:LINK
本篇教學的程式碼皆由筆者編輯,歡迎轉貼本教學,但請全文轉貼,謝啦~
沒有留言:
張貼留言