随笔分类 - c语言
教学中的一些程序和体会
摘要:源代码: #include <stdio.h>#define N 5 typedef struct Sqlist{ int num; char name[8];}Sqlist; int search(Sqlist R[],int n,int K){ int i; for(i=0;i<n;i++) i
阅读全文
摘要:源代码: #include <stdio.h>#include <stdlib.h>#define MAXSIZE 100 typedef struct cycqueue{ int data[MAXSIZE]; int front,rear; //声明队列的头指针和尾指针}CycQue; //队列的
阅读全文
摘要:源程序: #include <stdio.h>#define N 6 //功能:冒泡排序//作者:zhongliqi//编写时间:void bubble(int m[],int n){ int i,j,t; for(i=0;i<n;i++) { for(j=0;j<n-i-1;j++) { if(m
阅读全文
摘要:源程序: #include <stdio.h> //功能:两个数中找较大的//作者:chenminfang//编写时间://特殊技术:int max(int x,int y){ if(x>y) return x; else return y;} void main(){ int a,b,c,d,ma
阅读全文
摘要:源文件: #include <stdio.h>#include <stdlib.h>#include <string.h> //写函数 void writetext(FILE *fw){ char str[80]; gets(str); while(strcmp(str,"-1")!=0) { fp
阅读全文
摘要:源程序: #include <stdio.h>#include <stdlib.h>typedef struct node{ int data; struct node *next; //定义一个结构体,两部分,一个数据,一个指针}linklist; //主菜单void menu(){ printf
阅读全文
摘要:源程序: #include <stdio.h>#include <string.h>#define N 5 struct student //数据类型{ int num; //学号 char sname[25]; //姓名 char sex[4]; //性别 int age; //年龄}; stru
阅读全文
摘要:源程序: #include <stdio.h>#include <string.h>#include <stdlib.h> #define LINEMAX 20 /*定义字符串的最大长度*/ void sort(char** p) /*冒泡法对5个字符串排序函数*/{ int i, j; char
阅读全文
摘要:源程序: #include <stdio.h>#include <stdlib.h> //输出4个学生5门课程void print(int m[4][5]){ int i, j; for (i = 0; i < 4; i++) { for (j = 0; j < 5; j++) { printf("
阅读全文
摘要:源程序: #include <stdio.h> #include <stdlib.h> //在此处定义函数1. //在此处定义函数2. //在此处定义函数3. //在此处定义函数4. //菜单 void menu() { printf("\n*****************************
阅读全文
摘要:某一个班级有4名学生,每个学生有5门课程。分别编写3个函数实现如下要求: (1)求第一门课程的平均分; (2)找出有两门以上课程不及格的学生,输出他们的学号和全部课程成绩及平均成绩; (3)找出平均成绩在90分以上或全部课程成绩在85分以上的学生; 源代码: #include <stdio.h> /
阅读全文
摘要:源程序: #include <stdio.h> //求最大值的函数int highest(int m[3][4]) //形式参数是二维数组{ int a = m[0][0]; //认为第一个数是最大值 int i, j; for (i = 0; i < 3; i++) //外层循环控制行 { for
阅读全文
摘要:源程序: #include <stdio.h>int main(){ int upper=0,lower=0,digit=0,space=0,other=0,i=0; char *p,s[80]; printf("请输入一串字符,包括大写字母、小写字母、数字、空格和其他字符,不超过80个:\n");
阅读全文
摘要:源程序: #include <stdio.h>void main(){ int array[10]; int *pointer; int i,j,t,max,min,sum=0; double aver; int num1=0,num2=0; pointer=array; //指针指向数组,数组名表
阅读全文
摘要:源代码: #include <stdio.h>#include <stdlib.h>#define N 5 //函数与指针混合编程 void swap(int *pointer1, int *pointer2){ int temp; temp = *pointer1; *pointer1 = *po
阅读全文
摘要://利用二维数组打印出如下杨辉三角形的前8行。 #include <stdio.h>#define N 8void main(){ int i, j, k, n=0, a[N][N]; /*定义二维数组a[8][8]*/ while(n<=0||n>=8){ /*控制打印的行数不要太大,过大会造成显
阅读全文
摘要:源程序: //定义一个5行5列的二维数组,然后从键盘上输入数据对数组进行初始化,//求出该二维数组的四周元素的和。 #include <stdio.h>void main(){ int a[5][5],s,s1,i,j; /* s用来存放所有元素的和,s1用来存放中间元素的和 */ s=s1=0;
阅读全文
摘要:源代码: //定义一个包含4行4列的二维整型数组,要求从键盘上输入数据对数组进行初始化,然后//求出该二维数组所有元素的和以及每一行元素的平均值 #include <stdio.h>void main(){ int sum,s,i,j,a[4][4]; float aver; printf("请输入
阅读全文
摘要:源程序: #include <stdio.h>void main(){ int a[11]={12,21,27,30,35,44,56,60,68,70}; int i,j,data; printf("请输入要插入到数组中的整数:\n"); scanf("%d",&data); if(data<=a
阅读全文
摘要:源程序: void main(){ int a[10]={12,38,35,22,97,65,50,88,9,75}; int i,j,t; //t是临时变量 for(j=1;j<=9;j++) //外层循环控制第几趟排序 { for(i=0;i<=10-j-1;i++) //内层循环是比较两个数的
阅读全文