- 博客(9)
- 收藏
- 关注
原创 C语言求3-100内的孪生素数(素数之间相差为2表示孪生)
源代码: #include <stdio.h> int main() { int m,n=0,a=0,b=0; int num[100]; for(int i=3;i<100;i++){ for(int j=2;j<i;j++){ if(i%j==0) break; } if(j==i){ num[a]=i; a++; } ...
2022-03-31 16:24:29
3043
原创 用C语言打印行数为7的菱形
源代码: #include <stdio.h> int main() { int i,j,m,line=4; //打印菱形的上半部分 for(i=0;i<line;i++){ for(j=0;j<line-1-i;j++){ //输出空格 printf(" "); } for(m=0;m<2*i+1;m++){ //输出* printf("*"); ...
2022-03-31 15:34:48
3122
原创 C语言,利用头插法或者尾插法建立单链表
输入要建立的节点个数; 其中节点的数据值为创建其的序号; 源代码: #include <stdio.h> #include <stdlib.h> //定义链表结构体 typedef struct node{ int data; struct node *next; }node; int main(){ //创建单链表 struct node *head,*p,*q,*t; int i,j,n; head=(struct no...
2022-03-31 10:10:24
1714
原创 C语言创建一个单链表
源代码: #include <stdio.h> #include <stdlib.h> typedef struct node{ int data; struct node *next; }node; int main(){ struct node *head,*q,*p,*t; head=NULL; q=NULL; int a; for(int i=0;i<3;i++){ scanf("%d...
2022-03-31 00:20:05
1539
原创 利用结构体类型存储学生身份,利用某个关键字,进行排序。
源代码: #include <stdio.h> # include <string.h> typedef struct Student{ int num; char name[32]; int score[2]; int avg; }Student; int main(){ Student temp; int size = sizeof(temp); Student stu[3]; for(int i=0;i<3;...
2022-03-30 16:30:13
249
原创 创建一个有序链表,将一个元素插入到链表,并保证链表的有序性。
源代码: #include <stdio.h> #include <malloc.h> //定义结构体// typedef struct node{ int data; struct node *next; }node,*linklist; void nodeTest(){ struct node *head,*p,*q,*t; int i,n,a; head=p=NULL; scanf("%d",&n); for(i=0;i...
2022-03-30 11:00:23
386
原创 c语言实现折半查找,要求返回所在元素的下标。
如果不在数组中,则输出”不在数组中“ 在数组中,则返回数组下标。 源代码:#include <stdio.h> int nums[100]; int main(){ int n,a; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&nums[i]); } scanf("%d",&a); int low=0,high=n-1; while(low<high){ if(nums[(lo...
2022-03-29 23:46:39
454
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人