鐵之狂傲

 取回密碼
 註冊
搜尋

切換到指定樓層
1#
第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個偶數的值.
 
轉播0 分享0 收藏0

回覆 使用道具 檢舉

//第一題
#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;
}
 

回覆 使用道具 檢舉

你需要登入後才可以回覆 登入 | 註冊

存檔|手機版|聯絡我們|新聞提供|鐵之狂傲

GMT+8, 24-12-26 02:49 , Processed in 0.019135 second(s), 22 queries , Gzip On.

回頂部