当前位置:首页 » 编程语言 » c语言列表
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言列表

发布时间: 2022-01-25 10:12:00

c语言表示列表的问题

/*
抱歉,又是我
*/

//#define debug

struct dimension
{
int num_row ;
int num_col ;
} ;

void table_set_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col ,const int v)
{
if (t == 0 || dim == 0 || row < 0 || col < 0 || row >= dim->num_row || col >= dim->num_col)
return ;

t[col * dim->num_row + row] = v ;

return ;
}

int table_get_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col)
{
if (t == 0 || dim == 0 || row < 0 || col < 0 || row >= dim->num_row || col >= dim->num_col)
return 0 ;

return t[col * dim->num_row + row] ;
}

void table_clear (const int t[] ,struct dimension *dim)
{
if (t == 0 || dim == 0)
return ;

const int* pb = t ;
const int* pe = t + dim->num_row * dim->num_col ;
int* p ;

for (p = pb ; p < pe ; p++)
*p = 0 ;

return ;
}

void table_ (const int a[] ,const int b[] ,struct dimension *dim)
{
if (a == 0 || b == 0 || dim == 0)
return ;

const int* pab = a ;
const int* pae = a + dim->num_row * dim->num_col ;
int* pa ;

const int* pbb = b ;
int* pb ;

for (pa = pab ,pb = pbb ; pa < pae ; pa++ ,pb++)
*pb = *pa ;

return ;
}

#ifdef debug

int main ()
{
void table_set_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col ,const int v) ;
int table_get_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col) ;
void table_clear (const int t[] ,struct dimension *dim) ;
void table_ (const int a[] ,const int b[] ,struct dimension *dim) ;

int t[10][10] ;
int f[100] ;
const struct dimension dim = {10 ,10} ;
const int row = 4 ;
const int col = 7 ;
const int v = 250 ;

table_set_entry (t ,&dim ,row ,col ,v) ;

printf ("isn't %d equal to %d ?\n" ,t[col][row] ,table_get_entry (t ,&dim ,row ,col)) ;

table_ (t ,f ,&dim) ;
table_clear (t ,&dim) ;

printf ("t : %d while f : %d\n" ,t[col][row] ,f[col * dim.num_row + row]) ;

return 0 ;
}

#endif

② C语言函数列表

函数名: abort
功 能: 异常终止一个进程
用 法: void abort(void);
程序例:
#include <stdio.h>
#include <stdlib.h> int main(void)
{
printf("Calling abort()\n");
abort();
return 0; /* This is never reached */
}
函数名: abs
功 能: 求整数的绝对值
用 法: int abs(int i);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
int number = -1234; printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}
函数名: 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 <stdio.h>
#include <conio.h>
#include <process.h>
#include <dos.h> int main(void)
{
int i, strt, ch_out, sector;
char buf[512]; 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");
strt = 3;
for (i=0; i<80; i++)
{
ch_out = buf[strt+i];
putchar(ch_out);
}
printf("\n");
return(0);
}
函数名: access
功 能: 确定文件的访问权限
用 法: int access(const char *filename, int amode);
程序例:
#include <stdio.h>
#include <io.h> int file_exists(char *filename); int main(void)
{
printf("Does NOTEXIST.FIL exist: %s\n",
file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
return 0;
} int file_exists(char *filename)
{
return (access(filename, 0) == 0);
}
函数名: acos
功 能: 反余弦函数
用 法: double acos(double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = acos(x);
printf("The arc cosine of %lf is %lf\n", x, result);
return 0;
}
函数名: allocmem
功 能: 分配DOS存储
用 法: int allocmem(unsigned size, unsigned *seg);
程序例:
#include <dos.h>
#include <alloc.h>
#include <stdio.h> int main(void)
{
unsigned int size, segp;
int stat; size = 64; /* (64 x 16) = 1024 bytes */
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); return 0;
}
函数名: arc
功 能: 画一弧线
用 法: void far arc(int x, int y, int stangle, int endangle, int radius);
程序例:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h> int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int stangle = 45, endangle = 135;
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:");
getch(); exit(1); /* terminate with an error code */
} midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor()); /* draw arc */
arc(midx, midy, stangle, endangle, radius); /* clean up */
getch();
closegraph();
return 0;
}
函数名: asctime
功 能: 转换日期和时间为ASCII码
用 法: char *asctime(const struct tm *tblock);
程序例:
#include <stdio.h>
#include <string.h>
#include <time.h> int main(void)
{
struct tm t;
char str[80]; /* sample loading of tm structure */ t.tm_sec = 1; /* Seconds */
t.tm_min = 30; /* Minutes */
t.tm_hour = 9; /* Hour */
t.tm_mday = 22; /* Day of the Month */
t.tm_mon = 11; /* Month */
t.tm_year = 56; /* Year - does not include century */
t.tm_wday = 4; /* Day of the week */
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); return 0;
}
函数名: asin
功 能: 反正弦函数
用 法: double asin(double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = asin(x);
printf("The arc sin of %lf is %lf\n", x, result);
return(0);
}
函数名: assert
功 能: 测试一个条件并可能使程序终止
用 法: void assert(int test);
程序例:
#include <assert.h>
#include <stdio.h>
#include <stdlib.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 */
} int main(void)
{
additem(NULL);
return 0;
}
函数名: atan
功 能: 反正切函数
用 法: double atan(double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 0.5; result = atan(x);
printf("The arc tangent of %lf is %lf\n", x, result);
return(0);
}
函数名: atan2
功 能: 计算Y/X的反正切值
用 法: double atan2(double y, double x);
程序例:
#include <stdio.h>
#include <math.h> int main(void)
{
double result;
double x = 90.0, y = 45.0; result = atan2(y, x);
printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);
return 0;
}
函数名: atexit
功 能: 注册终止函数
用 法: int atexit(atexit_t func);
程序例:
#include <stdio.h>
#include <stdlib.h> void exit_fn1(void)
{
printf("Exit function #1 called\n");
} void exit_fn2(void)
{
printf("Exit function #2 called\n");
} int main(void)
{
/* post exit function #1 */
atexit(exit_fn1);
/* post exit function #2 */
atexit(exit_fn2);
return 0;
}
函数名: atof
功 能: 把字符串转换成浮点数
用 法: double atof(const char *nptr);
程序例:
#include <stdlib.h>
#include <stdio.h> int main(void)
{
float f;
char *str = "12345.67"; f = atof(str);
printf("string = %s float = %f\n", str, f);
return 0;
}
函数名: atoi
功 能: 把字符串转换成长整型数
用 法: int atoi(const char *nptr);
程序例:
#include <stdlib.h>
#include <stdio.h> int main(void)
{
int n;
char *str = "12345.67"; n = atoi(str);
printf("string = %s integer = %d\n", str, n);
return 0;
}
函数名: atol
功 能: 把字符串转换成长整型数
用 法: long atol(const char *nptr);
程序例: #include <stdlib.h>
#include <stdio.h> int main(void)
{
long l;
char *str = "98765432"; l = atol(lstr);
printf("string = %s integer = %ld\n", str, l);
return(0);
}

③ C语言动态列表排序

链表吗?以前练习的时候做过一个,你参考下

#include<stdio.h>

#include<stdlib.h>

#include<iostream.h>

#define OK 1;

#define ERROR 0;

typedef int ElemType;

typedef int Status;

typedef struct LNode{

ElemType data;

struct LNode *next;

}LNode,*LinkList;

void CreateList(LinkList &L,int n) //创建表

{

int i;

LNode *p;

L=(LinkList)malloc(sizeof(LNode));

L->next=NULL;

for(i=n;i>0;i--)

{

p=(LinkList)malloc(sizeof(LNode));

printf("输入第%d个元素的值 ",i);

scanf("%d",&p->data);

p->next=L->next;

L->next=p;

}

printf("创建成功! ");

}

Status GetElem(LinkList &L,int i) //得到第i个元素

{

ElemType j=1,e;

LNode *p;

p=L->next;

while(j<i&&p)

{

p=p->next;

j++;

}

if(!p||j>i)

{

printf("第%d个元素不存在! ",i);

return ERROR;

}

e=p->data;

printf("第%d个元素是%d ",i,e);

return OK;

}

Status ListInsert(LinkList &L,int i,ElemType e) //插入元素

{

ElemType j;

LNode *p,*s;

p=L;

j=1;

while(p&&j<i)

{

p=p->next;

++j;

}

if(!p||j>i)

{

printf("不能在第%d中插入 ",i);

}

s=(LinkList)malloc(sizeof(LNode));

s->data=e;

s->next=p->next;

p->next=s;

return OK;

}

Status ListDelete(LinkList &L,int i) //删除元素

{

LNode *p,*q;

p=L;

int j=0;

while(p->next&&j<i-1)

{

p=p->next;

j++;

}

if(!(p->next)||j>i-1)

{

printf("查找失败! ");

return ERROR;

}

q=p->next;

p->next=q->next;

free(q);

printf("删除成功! ");

return OK;

}

void MergeList(LinkList &La,LinkList &Lb,LinkList &Lc) //归并

{

LNode *pa,*pb,*pc;

Lc=pc=La;

pa=La->next;

pb=Lb->next;

while(pa&&pb)

{

if(pa->data<=pb->data)

{

pc->next=pa;

pc=pa;

pa=pa->next;

}

else

{

pc->next=pb;

pc=pb;

pb=pb->next;

}

}

pc->next=pa?pa:pb;

printf("归并成功! ");

}

void PList(LinkList &L) //打印

{

LNode *p;

p=L->next;

while(p)

{

printf("%d ",p->data);

p=p->next;

}

printf(" ");

}

Status CList(LinkList &L) //排序

{

LNode *p;

int flag,e;

p=L;

while(1)

{

flag=0;

for(p=L;p->next->next!=NULL;p=p->next)

{

if(p->next->data>p->next->next->data)

{

e=p->next->data;

p->next->data=p->next->next->data;

p->next->next->data=e;

flag=1;

}

}

if(flag==0)

{

printf("排序成功! ");

return OK;

}

}

}


int main()

{

int count=1,m,n,k,sum,i,j,g;

LinkList list[10];

printf("输入创建表的个数 ");

scanf("%d",&m);

for(;count<=m;count++)

{

printf("输入第%d个表的元素个数 ",count);

scanf("%d",&n);

printf("逆序输入n个元素 ");

CreateList(list[count],n);

printf("第%d个表创建成功 ",count);

}

sum=m+1;

while(1)

{

printf("功能: 1.查找某位置元素的值 2.插入元素 3.删除元素 4.元素排序 5.两表合并 6.显示表内元素 7.退出 ");

scanf("%d",&k);

switch(k)

{

case 1:

printf("输入查找的表 ");

scanf("%d",&i);

if(i>m)

{

printf("不存在表%d ",i);

break;

}

printf("输入查找位置 ");

scanf("%d",&j);

GetElem(list[i],j);

break;

case 2:

printf("输入要插入的表 ");

scanf("%d",&i);

if(i>m)

{

printf("不存在表%d ",i);

break;

}

printf("输入要插入的位置 ");

scanf("%d",&j);

printf("输入要插入的值 ");

scanf("%d",&g);

ListInsert(list[i],j,g);

break;

case 3:

printf("输入要删除的表 ");

scanf("%d",&i);

if(i>m)

{

printf("不存在表%d ",i);

break;

}

printf("输入要删除的位置 ");

scanf("%d",&j);

ListDelete(list[i],j);

break;

case 4:

printf("输入要排序的表 ");

scanf("%d",&i);

if(i>m)

{

printf("不存在表%d ",i);

break;

}

CList(list[i]);

break;

case 5:

printf("输入表1 ");

scanf("%d",&i);

if(i>m)

{

printf("不存在表%d ",i);

break;

}

printf("输入表2 ");

scanf("%d",&j);

if(i>m)

{

printf("不存在表%d ",j);

break;

}

MergeList(list[i],list[j],list[sum]);

printf("已经将合并的标放入第%d个表中",sum);

sum++;

m++;

break;

case 6:

printf("输入要显示的表 ");

scanf("%d",&i);

if(i>m)

{

printf("不存在表%d ",i);

break;

}

PList(list[i]);

break;

case 7:

return 0;

default:

printf("错误的指令!/n");

break;

}

}

}

④ C语言printf下各种%号列表

%d 按整型数据的实际长度输出
%md m是指输出字段的宽度。如果数据的位数小于m,则在左端补空格;若大于m,则按数据的实际位数输出。
%ld 输出长整型数据
%o 以八进制输出整型数
%x 以十六进制输出整型数
%u 以十进制输出unsigned型数据
%c 输出字符
%s 输出字符串
%ms 输出字符占m列,如果串长度小于m则左边补空格,若大于m则按原长度输出
%-ms 如果串长度小于m,则字符串相左靠,右边补空格
%m.ns 输出占m列,但只取字符串的左端n个字符。这n个字符在m的右侧,左边补空格
%-m.ns 其中m,n含义同上,n个字符输出在m列的左侧,右端补空格。如果n>m,则m自动取n值,即保证n个字符正常输出
%f 不指定字符宽度,由系统自动指定,使整数部分全部输出,并输出6位小数。应当注意输出的数字并非全部都是有效数字。单精度数的有效位数一般是7位,而双精度数的有效位数一般是16位。
%m.nf 指定输出的数列占m列,其中有n位小数。若数值长度小于m,左端补空格。
%-m.nf与%m.nf 的区别仅在于使输出的数值向左端靠,右端补空格。
%e 不指定输出数据所占的宽度和数字部分的小数位数
%m.ne和%-m.ne含义与前面相同
%g 假设一个数要用%f和%e输出,用%g格式时自动从这两种格式中选出最短者

⑤ C语言链表

#include<stdio.h>
#include<stdlib.h>
#defineN8
typedefstructlist
{intdata;
structlist*next;
}SLIST;
SLIST*insertlist(SLIST*p,int*pvalue)
{
SLIST*tmp=p,*tmp_p;
intt=*pvalue;
while(tmp->next!=NULL&&tmp->next->data<t)
tmp=tmp->next;

tmp_p=(SLIST*)malloc(sizeof(SLIST));
tmp_p->next=tmp->next;
tmp_p->data=t;
tmp->next=tmp_p;
returnp;
}

SLIST*creatlist(int*a)
{
SLIST*h,*p,*q;inti;
h=p=(SLIST*)malloc(sizeof(SLIST));
for(i=0;i<N;i++)
{q=(SLIST*)malloc(sizeof(SLIST));
q->data=a[i];
q->next=NULL;
p->next=q;
p=q;
}
p->next=0;
returnh;
}
voidoutlist(SLIST*h)
{
/*这里输出链表中各个数据*/
SLIST*tmp=h->next;
while(tmp!=NULL){
printf("%d",tmp->data);
tmp=tmp->next;
}
}
intmain(void)
{
SLIST*head;
inta[N];
intnvalue,i;
for(i=0;i<N;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&nvalue);//插入的结点数据
head=creatlist(a);
head=insertlist(head,&nvalue);
outlist(head);
return0;
}

⑥ c语言如何定义一个单项列表

#include<iostream>
usingnamespacestd;
structA
{
intx;
A*next;
};
A*Head;//头指针
intk=0;//记录创建链表个数
A*J_L();//创建链表
voidB_J(A*head,intx);//比较大小
voidshow(A*head);//输出
voidmain()
{
A*t;
t=J_L();
B_J(t,k);
show(t);
}
voidB_J(A*head,intx)
{
A*m,*n;
intswap;
for(inti=0;i<(x-1);i++)
{
n=head;
m=n->next;
for(intj=0;j<(x-i-1);j++)
{
if((n->x)>(m->x))
{swap=n->x;n->x=m->x;m->x=swap;}
n=n->next;
m=n->next;
}
}
}
voidshow(A*head)
{
A*t=head;
while(t!=NULL)
{
cout<<t->x<<endl;
t=t->next;
}
}
A*J_L()
{
cout<<"请输入,0退出";
A*p=newA;
k++;
A*d=Head=p;
cin>>p->x;
if(p->x==0)
{
k--;
deletep;Head=0;p=0;
}
while(1)
{
cout<<"请输入,0退出";
p=newA;
k++;
d->next=p;
cin>>p->x;
if(p->x==0)
{k--;deletep;d->next=0;p=0;break;}
d=p;
}
returnHead;
}

⑦ C语言 链表

/*

卡号 姓名

44098 谭侃

99089 马吹

23011 赵忽悠

q

44098 谭侃

99089 马吹

23011 赵忽悠

Press any key to continue

*/

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedefstructcard{
intcardnum;//卡号
charstudentname[30];//学生姓名
structcard*next;//指针域
}SCard;

SCard*Create(){
SCard*head,*p;
intid;
charname[30];
head=p=(SCard*)malloc(sizeof(SCard));
printf("卡号姓名 ");
while(scanf("%d%s",&id,name)==2){
p->next=(SCard*)malloc(sizeof(SCard));
p->next->cardnum=id;
strcpy(p->next->studentname,name);
p=p->next;
}
p->next=NULL;
returnhead;
}

voidShow(SCard*head){
SCard*p=head->next;
while(p){
printf("%d %s ",p->cardnum,p->studentname);
p=p->next;
}
}

intmain(){
SCard*head=Create();
if(head->next==NULL)printf("faileure ");
elseShow(head);
return0;
}

⑧ C语言如何建立一个列表,编程怎么编,举例说一下,谢谢啦

首先定义一个链表。

struct node
{
int id;
struct node * next;

};

接下来写一些操作的函数(插入,删除等等)。

插入函数:

struct node* insert(struct node* pNode, int iTemp)
{
//判断 pNode 是否为空。
if(pNode==NULL)
{
//这个节点是空,返回错误。
return NULL;

}
// 创建一个新的节点。

struct node* tempNode = (struct node*)malloc(sizeof(struct node));
tempNode->id= iTemp;
if(pNode->next == NULL)
{

pNode->next = tempNode;
tempNode->next = NULL;

}else
{
struct node * pNext = pNode->next;
pNode->next = tempNode;
tempNode->next = pNext;

}

return tempNode;

}

int main()
{
struct node* head = (struct node*)malloc(sizeof(struct node));
head->id = 0;
head->next = NULL;
struct node * ptemp;
ptemp = head;

for( int i=1; i<10; i++)
{
struct node* temp = insert(ptemp,i);
ptemp = temp;

}

return 0;

}

⑨ C语言链表···

struct date{…}/链表结构体
p1/定义链表结构体的一个指针名插入点/
p1=(struct date *)malloc(sizeof(struct date))/分配链表内存
free(newnode)/释放节点内存
删除全部节点定义两个链表指针名p1,p2循环删除
while(p1->next!=NULL)
{p2=p1;
p1->…/p1指向下链表一节点
free(p2);
}

⑩ c语言链表

嗨 又是个新注册的号 太不可信了 这年头新注册的号 真是不靠谱
没准辛辛苦苦做出来的题目 却被不了了之了 缺乏诚信啊