- 博客(88)
- 收藏
- 关注
原创 定义一个结构体变量(包括年、月、日)。计算该日在本年中是第几天,注意闰年问题。
#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>struct { int year; int month; int day;}data;int main() { int days; printf("请输入年、月、日:"); scanf_s("%d,%d,%d", &data.year, &da...
2021-02-24 17:57:12
1410
原创 口袋中有红、黄、蓝、白、黑5种颜色的球若干个。每次从口袋中先后取出3个球,问得到3种不同颜色的球的可能取法,输出每种排列情况
#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>int main() { enum Color { red, yellow, blue, white, black }; enum Color i, j, k, pri; int n, loop; n = 0; for(i=red;i<=b...
2021-02-24 17:22:23
1944
原创 有若干个人员的数据,其中有学生和教师。学生的数据中包括:姓名、号码、性别、职业和班级。教师的数据包括:姓名、号码、性别职业、职务。要求用同一个表格来处理。
#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>struct{ int num; char name[20]; char sex; char job; union { int clas; //班级 char position[10];//职务 }category;}pe...
2021-02-24 16:23:04
2203
原创 写一函数建立一个有三名学生的单向动态链表
#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>struct Student { long num; float score; struct Student *next;};int n;struct Student *creat(void){ struct Student *head;...
2021-02-23 20:07:08
168
原创 写一函数建立一个有三名学生的单向动态链表
#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>struct Student { long num; float score; struct Student *next;};int n;struct Student *creat(void){ struct Student *head;...
2021-02-23 20:07:08
457
原创 建立一个简单链表,由3个学生数据的节点组成,要求输出各节点中的数据
#include<stdio.h>#include<math.h>#include<string.h>struct Student { long num; float score; struct Student *next;};int main() { struct Student a, b, c, *head, *p; a.num = 10101; a.score = 89.5; ...
2021-02-23 17:42:45
1829
1
原创 有n个结构体变量,内含学生学号,姓名和3门课的成绩。要求输出平均成绩最高的学生的信息
#include<stdio.h>#include<math.h>#include<string.h>struct Student { long num; char name[20]; float score[3]; float aver;};void Input(struct Student stu[],int n) { int i; printf("请输入各学生的信息...
2021-02-23 17:27:17
2158
1
原创 有三个学生的信息,放在结构体数组中,要求输出全部学生的信息
#include<stdio.h>#include<math.h>#include<string.h>struct Student { long num; char name[50]; char sex; int age;}stu[3] = { {10101,"Li Lin",'M',18},{10102,"Zhang Feng",'M',19},{10104,"Wang Min",'F',...
2021-02-23 16:06:08
2617
原创 通过指向结构体变量的指针访问结构体变量中的成员
#include<stdio.h>#include<math.h>#include<string.h>struct Student { long num; char name[50]; char sex; float score;};int main() { struct Student stu_1; struct Student *p; p = &stu_...
2021-02-23 15:43:53
1594
原创 有n个学生信息(包括学号、姓名、成绩),要求按照成绩的高低顺序输出各学生的信息
#include<stdio.h>#include<math.h>#include<string.h>struct Student { long int num; char name[50]; float score;};int main() { struct Student stu[5] = { {10101,"zhang",78},{10103,"wang",98.5},{10106,"Li",...
2021-02-22 21:30:37
6574
1
原创 有三个候选人,每个选民只能投票选一人,要求编辑一个统计选票的程序,先后输入被候选人的名字,然后输出各得票结果
#include<stdio.h>#include<math.h>#include<string.h> struct Condition { char name[20]; int count; }leader[3] = { {"Li",0},{"Zhang",0},{"Sun",0} };int main() { int i, j; char leader_name[20]; ...
2021-02-22 21:02:10
4462
原创 输入两个学生的学号,姓名和成绩,输出较高成绩学生的学号,姓名和成绩。
#include<stdio.h>#include<math.h>#include<string.h>int main() { struct Student { long int num; char name[50]; float score; }student1,student2; scanf_s("%d%s%f", &student1.num, student1.name, &am...
2021-02-22 19:45:18
6265
原创 把一个学生的信息(包括学号,姓名,性别,住址)放在一个结构体变量中,然后输出这个学生的信息
#include<stdio.h>#include<math.h>#include<string.h>int main() { struct Student { long int num; char name[50]; char sex; char addr[100]; }a = {11001,"LiMing",'M',"Beijing Road"}; printf("...
2021-02-22 18:50:32
5394
原创 将数组a中n个数反序存放
#include<stdio.h>#include<math.h>#include<string.h>int main() { void Fanxu(int array[], int n); int a[10], i, j; printf("请输入10个数:");//3 7 9 11 0 6 7 5 4 2 for(i=0;i<10;i++){ scanf_s("%d", &a[i]); }...
2021-02-20 18:18:48
965
原创 输入10个学生5门课的成绩,分别用函数实现以下功能:
#include<stdio.h>#include<math.h>#include<string.h>float Student[10][5];int main() { void Stu_Ave(float Student[10][5]); void Cla_Ave(float Student[10][5]); void Max(float Student[10][5]); void fangcha(float Student...
2021-02-18 19:44:25
3151
2
原创 用递归方法求n阶勒让德多项式的值
#include<stdio.h>#include<math.h>#include<string.h>int main() { float LRD(int n, int x); int n, x; printf("请输入n,x:"); scanf_s("%d,%d", &n, &x); printf("%d阶勒让德多项式的值为:%6.2f\n", n, LRD(n, x));}float LRD(int...
2021-02-18 15:25:21
2996
原创 写一个函数,输入一行字符串,将此字符串最长的单词输出
#include<stdio.h>#include<math.h>#include<string.h>int main() { int longest(char str1[]); int alphabetic(char c); char str1[100]; int i; printf("请输入一个字符串:\n"); gets_s(str1); printf("最长单词:"); for (i = lon...
2021-02-17 18:16:11
1123
原创 输出四个数字字符,两两之间用空格隔开(如1990 输出1 9 9 0 )
#include<stdio.h>#include<math.h>#include<string.h>int main() { void kong(char str1[]); char str1[100];; printf("请输入4四个数字:");// gets_s(str1); kong(str1); printf("%s\n",str1);}void kong(char str1[]){ int i...
2021-02-17 17:23:45
2770
原创 将一个字符串中的元音字母复制到另一个字符串中
#include<stdio.h>#include<math.h>#include<string.h>int main() { void cpy(char str1[], char str2[]); char str1[100],str2[100]; printf("请输入字符串:");//abcdefg gets_s(str1); cpy(str1, str2); printf("元音:%s\n",str2);}...
2021-02-17 17:11:17
3063
原创 使字符串反序输出
#include<stdio.h>#include<math.h>#include<string.h>int main() { void inverse(char str1[]); char str1[100]; printf("请输入字符串:");//abcdefg gets_s(str1); inverse(str1); printf("新字符串:%s\n",str1);}void inverse(char ...
2021-02-17 16:19:45
211
原创 (全局变量)调用函数求成绩最高,最低,平均值
#include<stdio.h>#include<math.h>#include<string.h>float MAX, MIN ;int main() { float ave(float arry[], int n); float a[10]; printf("请输入十个同学的成绩:");//89 95 87.5 100 67.5 97 59 84 73 98 for (int i = 0; i < 10; i++) {...
2021-02-15 19:12:41
1564
原创 函数调用,选择排序
#include<stdio.h>#include<math.h>#include<string.h>int main() { void selectsort(int a[],int n); int a[10],n; printf("请输入十个数:");//45 2 9 0 -3 54 12 5 66 33 for (int i = 0; i < 10; i++) { scanf_s("%d", &a[i...
2021-02-15 18:31:45
826
原创 汉诺塔问题
#include<stdio.h>#include<math.h>#include<string.h>int main() { void Hanoi(int n, char one, char two, char three); int n; printf("请输入n:"); scanf_s("%d", &n); printf("盘子%d\n", n); Hanoi(n, 'A', 'B', 'C')...
2021-02-15 14:35:25
58
原创 (递归)五个学生,第五个学生比第四个学生大两岁,第四个学生比第三个学生大两岁……第一个学生10岁。
#include<stdio.h>#include<math.h>#include<string.h>int main() { int age(int a); int c; c = age(5); printf("第五个学生年龄为:%d", c);}int age(int a) { if (a == 1) return 10; else { return age(a - 1) + 2;...
2021-02-15 13:54:49
1008
原创 编写一个程序,将字符数组S2中的全部字符复制给S1中,不用strcpy函数。‘\0’也复制过去,‘\0’后面的不复制
#include<stdio.h>#include<math.h>#include<string.h>int main() { char str2[20] = { }; char str1[20]; int i=1; printf("请输入字符串1:"); gets_s(str1); while (str1[i]!='\0') { str1[i] ; i++; } ...
2021-02-11 20:10:17
1708
原创 编写一程序,将字符串s1与字符串s2比较,s1>s2,输出一正数,s1=s2,输出0,s1<s2,输出一负数,不要用strcpy,字符串用gets读入。输出的正负数的绝对值。
#include<stdio.h>#include<math.h>#include<string.h>int main() { char str2[20]; char str1[20]; int i = 0,j = 0,a,b; printf("请输入字符串1:"); gets_s(str1); printf("请输入字符串2:"); gets_s(str2); while (str2[i]!='\0'...
2021-02-11 19:33:57
1492
原创 编一程序,将两个字符串连接起来,不用strcat函数
#include<stdio.h>#include<math.h>#include<string.h>int main() { char str[20]; char str1[20]; int i = 0,j = 0; printf("请输入字符串1:");//country gets_s(str); printf("请输入字符串2:");//side gets_s(str1); while (str[...
2021-02-11 18:57:03
5425
原创 电文译成密文:A----Z,B----Y,a-----z,b-----y
#include<stdio.h>#include<math.h>#include<string.h>int main() { int j=0, n; char ch[80], tran[80]; printf("请输入原文:"); gets_s(ch); while (ch[j]!='\0') { if ((ch[j] >= 'A') && (ch[j] <= 'Z'))...
2021-02-11 18:22:58
454
原创 有一篇文章,共有三行文字,每行有80个字符。要求分别统计出其中英文大写字母,小写字母,数字,空格以及其他字符的个数
#include<stdio.h>#include<math.h>#include<string.h>int main() { char txt[3][80]; int daxie=0, xiaoxie=0, shuzi=0, kongge=0, qita=0; for (int i = 0; i < 3; i++) { printf("请输入第%d行文字:",i+1);//I am a student. 123456 ...
2021-02-10 21:18:33
3313
4
原创 有十五个数按大到小顺序存放在一个数组中,输入一个数,要求用折半查找法找出该数是数组中第几个元素的值。
#include<stdio.h>#include<math.h>#include<string.h>int main() { int i,m, a[15],sign; int high=15, low=1,mid=0; printf("请输入15个数(由大到小):");//15 14 13 12 11 10 9 8 7 6 5 4 3 2 1//1 3 4 5 6 8 12 23 34 44 45 56 57 58 68 for ...
2021-02-10 20:17:48
4912
原创 找出一个二维数组中的鞍点,即该位置上的元素在该行最大,该列最小。也可能没有鞍点
#include<stdio.h>#include<math.h>#include<string.h>int main() { int i, j, k, a[4][5], maxj, max, flag; printf("请输入数组:"); for (i = 0; i < 4; i++) { for (j = 0; j < 5; j++) scanf_s("%d", &a[i][j]...
2021-02-10 18:53:09
6400
1
原创 输出魔方阵
所谓魔方阵是指它的每一行每一列和对角线之和均相等。#include<stdio.h>#include<math.h>#include<string.h>int main() { int n,i,j,k,p=1; int a[15][15]; while (p==1) { printf("请输入n阶方程(n一般为1---15内奇数):"); scanf_s("%d", &n); ...
2021-02-09 15:37:07
198
原创 输出杨辉三角前十行
#include<stdio.h>#include<math.h>#include<string.h>int main() { int i, j, a[10][10]; for (i = 0; i < 10; i++) { a[i][i] = 1; a[i][0] = 1; } for (i = 2; i < 10; i++) for (j = 1; j <= i - ...
2021-02-09 15:03:17
848
原创 将一个数组中的值逆序存放
#include<stdio.h>#include<math.h>#include<string.h>int main() { int a[10]; int x; printf("请输入一个数组:"); //1 4 6 9 13 16 19 28 40 100 for (int i = 0; i <= 9; i++) { scanf_s("%d", &a[i]); } printf("该数...
2021-02-09 14:36:20
1444
原创 有一个已排好序的数组,要求输入一个数后,按原来排序规律将他插入数组。
#include<stdio.h>#include<math.h>#include<string.h>int main() { int a[11]; int x; printf("请输入一个已排好序的数组:"); //1 4 6 9 13 16 19 28 40 100 for (int i = 0; i < 10;i++) { scanf_s("%d", &a[i]); printf("...
2021-02-09 14:30:35
3698
原创 求3*3矩阵对角线之和
#include<stdio.h>#include<math.h>#include<string.h>int main() { int a[3][3]; int sum=0; printf("请输入一个3*3的矩阵:"); //8,1,6,3,5,7,4,9,2 1 2 3 4 5 6 7 8 9 for (int i = 0; i < 3;i++) { for (int j = 0; j < 3; j++...
2021-02-09 14:00:42
624
原创 选择排序
#include<stdio.h>#include<math.h>#include<string.h>int main() { int a[10]; int i, j, min, max, temp; printf("请输入十个数:");//1 16 5 98 23 119 18 75 65 81 for (i = 0; i < 10; i++) { scanf_s("%d", &a[i]); }...
2021-02-07 22:05:42
99
1
原创 用筛选法求100之内的素数
筛选法指“埃拉托色尼筛法”,即在一张纸上写上1-1000的全部整数,然后逐个判断它们是否为素数,找出一个非素数,就把它挖掉,最后剩下的就是素数。#include<stdio.h>#include<math.h>#include<string.h>int main() { int a[100]; int i,j; for (i = 0; i < 100; i++) { a[i] = i; } for (...
2021-02-07 20:53:14
1528
原创 三个字符串,输出最大的
#include<stdio.h>#include<math.h>#include<string.h>int main() { char str[3][20]; char temp[20]; printf("请输入三个字符串:");//Holland,China,America for (int i = 0; i <= 2; i++) { gets_s(str[i]); } if (strcmp(...
2021-02-07 16:43:44
2875
原创 输入一行字符,统计其中有多少个单词,单词之间用空格分开
#include<stdio.h>#include<math.h>int main() { char str[100]; int sum=0; printf("请输入一串字符:");//I am a boy; gets_s(str); for (int j = 0; str[j]!='\0'; j++) { if (str[j] == ' ') sum++; } printf...
2021-02-07 16:06:16
1155
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人