日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言函数介绍

發(fā)布時間:2023/12/20 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言函数介绍 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.字母的大小寫轉換-->islower()

2.快速排序函數(shù)-->qsort()

下面正式給大家介紹這兩個函數(shù)

(1)islower()

islower() 函數(shù)用來檢測一個字符是否是小寫字母。

在默認情況下,小寫字母包括:

a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z

?

檢測到是小寫字母時可以將它轉換為大寫字母,具體我們可以用一個實例來看看。

1.KiKi想完成字母大小寫轉換,有一個字符,判斷它是否為大寫字母,如果是,將它轉換成小寫字母;反 之則轉換為大寫字母。

輸入描述:?多組輸入,每一行輸入一個字母。

輸出描述:針對每組輸入,輸出單獨占一行,輸出字母的對應形式

示例1

輸入

a

A

Z

輸出

A

a

z

參考代碼:

#include <stdio.h> int main() {int ch = 0;//多組輸入while((ch=getchar()) != EOF){if(islower(ch)){printf("%c\n", toupper(ch));}else{printf("%c\n", tolower(ch)); }//處理'\n'getchar();}return 0; }

這里強調一下,toupper()的意思是將小寫字母轉換為大寫字母,tolower()的意思是將大寫字母轉換為小寫字母!

(2)qsort()

C 庫函數(shù)?void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*))?對數(shù)組進行排序。

需要頭文件:#include<stdlib.h>或#include<search.h>

具體介紹如下:

?

Remarks

The qsort function implements a quick-sort algorithm to sort an array of num elements, each of width bytes. The argument base is a pointer to the base of the array to be sorted. qsort overwrites this array with the sorted elements. The argument compare is a pointer to a user-supplied routine that compares two array elements and returns a value specifying their relationship. qsort calls the compare routine one or more times during the sort, passing pointers to two array elements on each call:

compare( (void *) elem1, (void *) elem2 );

The routine must compare the elements, then return one of the following values:

Return ValueDescription
< 0elem1 less than elem2
0elem1 equivalent to elem2
> 0elem1 greater than elem2

The array is sorted in increasing order, as defined by the comparison function. To sort an array in decreasing order, reverse the sense of “greater than” and “l(fā)ess than” in the comparison function.

?舉個實例:

題目描述:

期中考試開始了,大家都想取得好成績,爭奪前五名。從鍵盤輸入n個學生成績(不超過40個),輸出 每組排在前五高的成績。

輸入描述:

兩行,第一行輸入一個整數(shù),表示n個學生(>=5),第二行輸入n個學生成績(整數(shù)表示,范圍0~100),用 空格分隔。

輸出描述:

一行,輸出成績最高的前五個,用空格分隔。

示例:

輸入:

6

99 45 78 67 72 88

輸出

99 88 78 72 67

參考代碼:

#include <stdio.h> int cmp_int(const void* e1, const void*e2) {return *(int*)e1 - *(int*)e2; } int main() {int n = 0;int score[40] = {0};scanf("%d", &n);int i = 0;for(i=0; i<n; i++){scanf("%d", &score[i]);}//對所有數(shù)字排序int j = 0;//使用庫函數(shù)排序qsort(score, n, 4, cmp_int);for(i=0; i<5; i++){printf("%d ", score[--n]);}return 0; }

以上就是今天的分享了,對你有幫助,點個關注謝謝。

總結

以上是生活随笔為你收集整理的C语言函数介绍的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。