网站首页 > 文章中心 > 其它

c语言最简单的函数

作者:小编 更新时间:2023-09-01 19:39:58 浏览量:21人看过

用最简单的c语言编写一个函数,要求初学者能看懂的,谢谢

给你举个完整的例子吧 上面的指针之类的应该还没学到吧~

# include"stdio.h"

# include"string.h"/*因为引用了函数strlen()*/

void string_change(char str[])

{

char c;

int i,j;

for(i=0,j=strlen(str)-1;;i++,j--)/*strlen(str)这是取该字符组的长度*/

if(ij)

{c=str[i];str[i]=str[j];str[j]=c;}/*中心对称互换*/

if(ij)break; /*结束循环*/

}

void main()

char str[100];/*里面的100自己取的注意输入不要超过就行*/

printf("请输入字符组:\n");

gets(str);

string_change(str); /*引用函数进行对换*/

puts(str);/*输出对换后的字符组*/

C语言,调用函数最简单例子

①.,调用非自身函数

void main(){

int n=0;

n=fun(n);

printf("%d",n);

int fun(int n){

if(n==0){

return 1;

}else{

return 0;

if(n==1){

return n+fun(n-1);

最简单的C语言代码

最简单的C语言代就是输出"helloWord",通常是作为初学编程语言时的第一个程序代码.具体代码如下:

#include stdio.h

int main(){

printf("Hello, World! \n");

扩展资料:

①.、程序的第一行#include stdio.h是预处理器指令,告诉 C 编译器在实际编译之前要包含 stdio.h 文件.

求C语言函数大全

函数名: abort

功 能: 异常终止一个进程

用 法: void abort(void);

程序例:

#include stdlib.h

int main(void)

printf("Calling abort()\n");

abort();

return 0; /* This is never reached */

函数名: abs

功 能: 求整数的绝对值

用 法: int abs(int i);

#include math.h

printf("number: %d absolute value: %d\n", number, abs(number));

函数名: absread, abswirte

功 能: 绝对磁盘扇区读、写数据

用 法: int absread(int drive, int nsects, int sectno, void *buffer);

int abswrite(int drive, int nsects, in tsectno, void *buffer);

/* absread example */

#include conio.h

#include process.h

#include dos.h

int i, strt, ch_out, sector;

printf("Insert a diskette into drive A and press any key\n");

getch();

sector = 0;

if (absread(0, 1, sector, buf) != 0)

perror("Disk problem");

exit(1);

printf("Read OK\n");

ch_out = buf[strt+i];

putchar(ch_out);

printf("\n");

return(0);

函数名: access

功 能: 确定文件的访问权限

用 法: int access(const char *filename, int amode);

#include io.h

int file_exists(char *filename);

printf("Does NOTEXIST.FIL exist: %s\n",

file_exists("NOTEXISTS.FIL") ? "YES" : "NO");

int file_exists(char *filename)

return (access(filename, 0) == 0);

函数名: acos

功 能: 反余弦函数

用 法: double acos(double x);

double result;

result = acos(x);

printf("The arc cosine of %lf is %lf\n", x, result);

函数名: allocmem

功 能: 分配DOS存储段

用 法: int allocmem(unsigned size, unsigned *seg);

#include alloc.h

unsigned int size, segp;

int stat;

stat = allocmem(size, segp);

if (stat == -1)

printf("Allocated memory at segment: %x\n", segp);

else

printf("Failed: maximum number of paragraphs available is %u\n",

stat);

函数名: arc

功 能: 画一弧线

用 法: void far arc(int x, int y, int stangle, int endangle, int radius);

#include graphics.h

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int midx, midy;

int radius = 100;

/* initialize graphics and local variables */

initgraph(gdriver, gmode, "");

/* read result of initialization */

errorcode = graphresult(); /* an error occurred */

if (errorcode != grOk)

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

exit(1); /* terminate with an error code */

setcolor(getmaxcolor());

/* draw arc */

arc(midx, midy, stangle, endangle, radius);

/* clean up */

closegraph();

函数名: asctime

功 能: 转换日期和时间为ASCII码

用 法: char *asctime(const struct tm *tblock);

#include string.h

#include time.h

struct tm t;

/* sample loading of tm structure */

t.tm_sec = 1; /* Seconds */

t.tm_mon = 11; /* Month */

t.tm_yday = 0; /* Does not show in asctime */

t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */

/* converts structure to null terminated

string */

strcpy(str, asctime(t));

printf("%s\n", str);

函数名: asin

功 能: 反正弦函数

用 法: double asin(double x);

result = asin(x);

printf("The arc sin of %lf is %lf\n", x, result);

函数名: assert

功 能: 测试一个条件并可能使程序终止

用 法: void assert(int test);

#include assert.h

struct ITEM {

int key;

int value;

};

/* add item to list, make sure list is not null */

void additem(struct ITEM *itemptr) {

assert(itemptr != NULL);

/* add item to list */

additem(NULL);

函数名: atan

功 能: 反正切函数

用 法: double atan(double x);

result = atan(x);

printf("The arc tangent of %lf is %lf\n", x, result);

功 能: 计算Y/X的反正切值

printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);

函数名: atexit

功 能: 注册终止函数

用 法: int atexit(atexit_t func);

void exit_fn1(void)

printf("Exit function #1 called\n");

/* post exit function #1 */

atexit(exit_fn1);

函数名: atof

功 能: 把字符串转换成浮点数

用 法: double atof(const char *nptr);

float f;

f = atof(str);

printf("string = %s float = %f\n", str, f);

函数名: atoi

功 能: 把字符串转换成长整型数

用 法: int atoi(const char *nptr);

int n;

n = atoi(str);

printf("string = %s integer = %d\n", str, n);

函数名: atol

用 法: long atol(const char *nptr);

long l;

l = atol(lstr);

printf("string = %s integer = %ld\n", str, l);

c语言十个基本函数

main函数——主函数;

printf函数——格式输出函数;

scanf函数——格式输入函数;

getchar函数——字符输入函数;

putchar函数——字符输出函数;

gets函数——字符串输入函数;

puts函数——字符串输出函数;

strlen函数——求字符串长度的函数;

strcmp函数——比较字符串的函数;

sqrt函数——求开平方值的函数.

你说要十个的,所以我就写了十个!!这些,本人认为都是基础的函数!!

以上就是土嘎嘎小编为大家整理的c语言最简单的函数相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章