C语言函数介绍

article/2025/9/21 23:41:21

1.字母的大小写转换-->islower()

2.快速排序函数-->qsort()

下面正式给大家介绍这两个函数

(1)islower()

islower() 函数用来检测一个字符是否是小写字母。

在默认情况下,小写字母包括:

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 库函数 void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*)) 对数组进行排序。

需要头文件:#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 “less than” in the comparison function.

 举个实例:

题目描述:

期中考试开始了,大家都想取得好成绩,争夺前五名。从键盘输入n个学生成绩(不超过40个),输出 每组排在前五高的成绩。

输入描述:

两行,第一行输入一个整数,表示n个学生(>=5),第二行输入n个学生成绩(整数表示,范围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]);}//对所有数字排序int j = 0;//使用库函数排序qsort(score, n, 4, cmp_int);for(i=0; i<5; i++){printf("%d ", score[--n]);}return 0;
}

以上就是今天的分享了,对你有帮助,点个关注谢谢。


http://chatgpt.dhexx.cn/article/A4B3u23n.shtml

相关文章

C语言标准库函数大全(ctype、time 、stdio、stdlib、math、string)

文章目录 C语言函数库:一. <ctype.h>二. <math.h>三. <stdio.h>四. <stdlib.h>五. <time.h>六. <string.h> 文档资料 C语言函数库: C语言的常用的标准头文件有 &#xff1a; <ctype.h>   <time.h>   <stdio.h> <…

【C语言进阶】最常用的库函数大全——从入门到精通

目录 前言&#xff1a; 一.字符串函数 1.strlen——求字符串长度 strlen 2.长度不受限制的字符串函数 a.strcpy——字符串拷贝 strcpy b.strcat——追加字符串 strcat c.strcmp——字符串比较 strcmp 3.长度受限制的字符串函数——strncpy,strncat,strncmp 为什么会…

C语言一些常用的函数

目录 sizeof()运算符strlen()函数abort()函数exit()函数Sleep()函数atof()将字符串转换成浮点数atoi()将字符串转换成整型数的函数atol()将字符串转换成长整型数的函数strlwr()函数strupr()函数 sizeof()运算符 sizeof()运算符: 编译器自带的,不用到任何包都能用。用法&…

C语言常用函数详解

函数详解&#xff1a; strlen(字符串长度)sizeof(字节大小)strcmp(字符串比较)strcpy(字符串拷贝)strcat(字符串追加)strncpy(字符串按字节拷贝)strncmp(字符串按字节比较)strncat(字符串按字节追加)strstr(查找字符串)strtok(查找符号)memcpy(按字节拷贝数据&#xff08;任意类…

C语言的中常用的函数

一、main函数 一个C程序就是由若干头文件和函数组成&#xff0c;有且只有一个主函数&#xff0c;即main函数。 #include <stdio.h>int main(){printf("c语言主函数");return 0; } C程序就是执行主函数里的代码&#xff0c;C语言中的唯一入口。 main前面的int…

C语言中常用的函数

C语言中常用的函数 1、putchar()函数2、getchar()函数3、pow( a , b )函数4、sqrt( a )函数5、fabs(a)函数6、puts(字符数组)函数——输出字符串的函数7、gets(字符数组)——输入字符串的函数8、strcat(a , b)函数——字符串连接函数9、strcpy函数——字符串复制函数10、strncp…

C语言中的函数(详解)

目录 1.函数是什么 2.c语言中函数的分类&#xff1a; 2.1. 库函数 2. 自定义函数 3. 函数的参数 3.1 实际参数&#xff08;实参&#xff09; 3.2 形式参数&#xff08;形参&#xff09; 4. 函数的调用&#xff1a; 4.1 传值调用 4.2 传址调用 5. 函数的嵌套调用和链…

linux Ubuntu将默认bash修改为csh

Ubuntu将默认bash修改为csh 前言Linux系统中的shell版本问题修改方法bash切换csh方法 前言 为什么要将默认bash修改为csh&#xff0c;有时候安装的软件命令是基于csh写的&#xff0c;如果用bash使用软件就会报错&#xff0c;如&#xff1a;“No command ‘setenv’ found”&…

配置你的 csh/tcsh

配置你的 csh/tcsh 选择 csh/tcsh 和许多刚从 Linux 转到 BSD 的人不同&#xff0c;我并没有装完 BSD 就顺手安装 bash&#xff0c;因为之前除了打命令&#xff0c;我没有用到额外的功能&#xff0c;bash 也好&#xff0c;csh 也罢&#xff0c;在我眼里都是当做 shell 来用。但…

bash 和 tcsh(csh)的不同,带例子

我使用bash和tcsh(csh)过程中总结出的一些异同&#xff0c;附我的彩色的提示行配置 效果&#xff1a; 自做的彩色提示符 bash PS1 命令提示符 ## PS1\[\033[01;33m\][\D{%y-%m-%d} \t]\[\033[00m\]\[\033[01;32m\][\!]\[\033[00m\]${debian_chroot:($debian_chroot)}\[\03…

Bash与Csh的区别

zz &#xff1a;http://dangdanding.blog.163.com/blog/static/27992981201262595221896/ 一、csh的while循环控制结构及if then: #!/bin/csh -f while ($#argv > 1) if ("$1" "-s") then shift if ($#argv > 1) then set source …

CSH脚本学习

CSH脚本学习笔记(不常见的命令用法) csh中的 > ! 命令与bash中的> 和>| 命令相同&#xff0c;都是写入文件内容。但在bash中表示没有文件则不创建文件。 foreach var &#xff08; list ) command end 是CSH脚本中的循环命令&#xff0c;将list的值逐一赋值给变量var…

Shell编程之Csh和Bash的经验总结

文章目录 前言1. 变量和环境变量设置1. csh2. bash 2. if语句1. csh2. bash 3. while循环1. csh2. bash 4. 数组1. csh2. bash 5. 获取当前文件路径1. csh2. bash 6. 获取当前时间1. csh2. bash 7. 产生随机数并测试1. csh2. bash 8. 补充1. 查看系统默认用的 Shell2. 查看系统…

矩阵转置基本性质

一个矩阵的转置与本身相乘得到对称矩阵 一个矩阵的逆矩阵与本身相乘得到单位矩阵 行列式不等于零&#xff0c;矩阵可逆&#xff0c;反之不可逆 满秩矩阵一定是可逆的

Maple: 矩阵转置

在Maple中用%T的命令执行矩阵转置&#xff0c;具体效果如下

5*5矩阵转置

编写程序&#xff1a;对一个5X5的二维整型数组转置&#xff0c;即行列互换。 要求从键盘输入数组的值&#xff0c;输出转置前及转置后的结果。 如&#xff1a; 输入格式: 输入数组前有如图示的提示&#xff1b; 输出格式: 输出转置前及转置后的结果&#xff0c;输出前有提示…

矩阵转置输出

输入样例 3 2 1 2 3 4 5 6 #include<stdio.h> int main() {int m,n;int a[15][15]{0};//二维数组int i,j;scanf("%d %d",&m,&n);for(i0;i<m;i)for(j0;j<n;j)scanf("%d",&a[i][j]);//先全部输入再进行其他操作for(i0;i<m;i){for…

c语言函数矩阵转置代码,C语言实现矩阵转置

讲解对象&#xff1a;C语言实现矩阵转置 作者&#xff1a;融水公子 rsgz 1随机函数生成矩阵 #include #include #include int main(){ int i,j; int a[5][3]; printf("生成矩阵:\n"); //srand(time(NULL)); for(i0;i<5;i){ for(j0;j<3;j){ a[i][j]rand()%20; }…

vue报错:Failed to resolve directive: modle

问题原因&#xff1a;我把model写成了modle

[Vue warn]: Failed to resolve directive: modle (found in ComponentA)

报错原因&#xff1a;单词拼写错误 解决方法&#xff1a;检查是否将model写成了modle 温馨提示&#xff1a;编写代码要细心且严谨&#xff08;这已经是我第二次犯类似的错误了&#xff09;