鐵之狂傲

標題: C語言程式題目 (請大大們幫忙解) [列印本頁]

作者: gamegx90153    時間: 06-12-9 11:15
標題: C語言程式題目 (請大大們幫忙解)
第1題: 給同學一個二維字元陣列
char string_data[12][50]={
"Course",
"Computer Tech.",
"How are you?",
"Watch out!",
"A piece of cake",
"Certified ",
"had never seen",
"starred roof",
"When it rains, it pours",
"What are we going to do",
"it seems like",
"burning the midnight oil"
};
請同學做兩件事情:
1.將這12個字串以strcmp作由小到大的排序,完成後string_data[0]應指向
一個經過strcmp比較後最小的字串。
2.將排序完的結果,對這12個字串作reverse,例如:Course變成esruoC
最後把這12個字串印出來。
//--------------------------------
第2題:
設整數陣列 arr 宣告為
int arr[5]={34, 76, 33, 42, 76};
請利用指標常數arr的運算, 找出並印出arr中第2個偶數的值.
作者: turnX    時間: 06-12-21 05:10
//第一題
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char string_data[12][50]={
"Course",
"Computer Tech.",
"How are you?",
"Watch out!",
"A piece of cake",
"Certified ",
"had never seen",
"starred roof",
"When it rains, it pours",
"What are we going to do",
"it seems like",
"burning the midnight oil"
};
int cmp(const void * a,const void * b)
{
return  strcmp( (char *)a,(char *)b );
}
int main()
{
int i;
qsort(string_data,12,sizeof(string_data[0]),cmp);
for(i=0;i<12;i++)
  printf("%s\n",strrev(string_data));
return 0;
}




歡迎光臨 鐵之狂傲 (https://gamez.com.tw/)