公告版位
星落的瞬間!放棄的後悔是永遠!

目前日期文章:200905 (34)

瀏覽方式: 標題列表 簡短摘要
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
第一題 (magic.c)#include <stdio.h> #include <stdlib.h> int question1(){ int matA[10][10] = {0}; int mat3[3][3] = { {7,11,6}, { 7, 8,9}, {10, 5,9} }; int i,j; printf("What this matrix's magic number?\n"); for (i = 0;i < 3;i++) { for (j = 0;j < 3;++j) { matA[i][j]=mat3[i][j]; printf("%3d",matA[i][j]); } printf("\n"); } printf("This matrix's magic is %d.\n",magic(matA,3)); system("pause"); return 0;}int magic(int A[][10], int n){ int sum=0,i,j,tmp; for (i = 0;i < n;++i) { sum+=A[0][i]; } for (i = 0;i < n;++i) { tmp = 0; for (j = 0;j < n;++j) { tmp += A[i][j]; } if (tmp != sum) return 0; tmp = 0; for (j = 0;j < n;++j) { tmp += A[j][i]; } if (tmp != sum) return 0; } tmp=0; for (i = 0;i < n;++i) { tmp += A[i][i]; } if (tmp != sum) return 0; tmp=0; for (i = 0;i < n;++i) { tmp += A[n-i-1][i]; } if (tmp != sum) return 0; return sum;}第二題 (MinMaxAvg.c)#include <stdio.h> #include <stdlib.h> void MinMaxAvg(int values[], int n, int* min, int* max, double* avg);int question2(){ int v[] = {0,11,22,33,44,55,66,77,88,99}; int min,max,i; double avg; MinMaxAvg(v,10,&min,&max,&avg); printf("What is the min,max and avg in this Array?\n"); for (i = 0;i < 10;++i) { printf("%3d",v[i]); } printf("\nmin= %d , max= %d , avg = %lf\n",min,max,avg); system("pause"); return 0;}void MinMaxAvg(int values[], int n, int* min, int* max, double* avg){ int i,sum = 0,_min = values[0],_max = values[0]; double _avg; for (i = 0;i < n;++i) { _min = (_min > values[i])?values[i]:_min; _max = (_max < values[i])?values[i]:_max; sum += values[i]; } _avg = (double)sum / n; *min = _min; *max = _max; *avg = _avg;}第三題 (StringCompare.c)#include <stdio.h> #include <stdlib.h> #include <string.h> int question3(){ char string1[100] = {0}; char string2[100] = {0}; printf("Enter string1:"); scanf("%s",string1); printf("Enter string2:"); scanf("%s",string2); printf("%s ",string1); switch (strcmp(string1,string2)) { case 1: printf(">"); break; case 0: printf("="); break; case -1: printf("<"); break; } printf(" %s\n",string2); system("pause"); return 0;}第四題 (Convert.c)#include <stdio.h> #include <stdlib.h> #include <string.h> char* NumToStr(long n);char* Convert(const long n);int question4(){ long input; printf("Enter any 1-9 digit number: "); scanf("%ld",&input); printf("%s\n",Convert(input)); system("pause"); return 0;}char* Convert(const long n){ char tmp[200] = ""; if (n>=0) { if (n <= 20) { return NumToStr(n); } else if (n < 100) { if (n % 10 == 0) { return NumToStr(n); } else { strcat(tmp,NumToStr(n/10*10)); strcat(tmp,"-"); strcat(tmp,NumToStr(n%10)); return tmp; } } else if (n < 1000) { if (n % 100 == 0) { strcat(tmp,NumToStr(n/100)); strcat(tmp," "); strcat(tmp,NumToStr(100)); return tmp; } else { strcat(tmp,NumToStr(n/100)); strcat(tmp," "); strcat(tmp,NumToStr(100)); strcat(tmp," "); strcat(tmp,Convert(n%100)); return tmp; } } else if (n < 1000000) { if (n % 1000 == 0) { strcat(tmp,Convert(n/1000)); strcat(tmp," "); strcat(tmp,NumToStr(1000)); return tmp; } else { strcat(tmp,Convert(n/1000)); strcat(tmp," "); strcat(tmp,NumToStr(1000)); strcat(tmp," "); strcat(tmp,Convert(n%1000)); return tmp; } } else if (n >= 1000000) { if (n % 1000000 == 0) { strcat(tmp,Convert(n/1000000)); strcat(tmp," "); strcat(tmp,NumToStr(1000000)); return tmp; } else { strcat(tmp,Convert(n/1000000)); strcat(tmp," "); strcat(tmp,NumToStr(1000000)); strcat(tmp," "); strcat(tmp,Convert(n%1000000)); return tmp; } } } else { return "I don't know"; }}char* NumToStr(const long n){ switch (n) { case 0: return "zero"; break; case 1: return "one"; break; case 2: return "two"; break; case 3: return "three"; break; case 4: return "four"; break; case 5: return "five"; break; case 6: return "six"; break; case 7: return "seven"; break; case 8: return "eight"; break; case 9: return "nine"; break; case 10: return "ten"; break; case 11: return "eleven"; break; case 12: return "twelve"; break; case 13: return "thirteen"; break; case 14: return "forteen"; break; case 15: return "fifteen"; break; case 16: return "sixteen"; break; case 17: return "seventeen"; break; case 18: return "eighteen"; break; case 19: return "nineteen"; break; case 20: return "twenty"; break; case 30: return "thirty"; break; case 40: return "forty"; break; case 50: return "fifty"; break; case 60: return "sixty"; break; case 70: return "seventy"; break; case 80: return "eighty"; break; case 90: return "ninety"; break; case 100: return "hundred"; break; case 1000: return "thousand"; break; case 1000000: return "million"; break; }}

讓地獄深紅的天亮 發表在 痞客邦 PIXNET 留言(0) 人氣()

  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
  • 這是一篇限定好友觀看的文章,若您為好友請先登入才可閱讀
1 2