gamegx90153 發表於 06-12-9 11:15:27

C語言程式題目 (請大大們幫忙解)

第1題: 給同學一個二維字元陣列
char string_data={
"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應指向
一個經過strcmp比較後最小的字串。
2.將排序完的結果,對這12個字串作reverse,例如:Course變成esruoC
最後把這12個字串印出來。
//--------------------------------
第2題:
設整數陣列 arr 宣告為
int arr={34, 76, 33, 42, 76};
請利用指標常數arr的運算, 找出並印出arr中第2個偶數的值.

turnX 發表於 06-12-21 05:10:20

//第一題
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char string_data={
"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),cmp);
for(i=0;i<12;i++)
  printf("%s\n",strrev(string_data));
return 0;
}
頁: [1]
檢視完整版本: C語言程式題目 (請大大們幫忙解)