C语言练习
Drscq
STRIVE FOR MY DREAM
展开
-
A special mistake when using FILE(how to reset the file pointer)
The descripetion of my problem:Segmentation fault (core dumped)The corresponding codes:#include <iostream>#include <stdio.h>#include <cstring>int main() { //build a directory named data in first level /*std::string path = "...原创 2022-02-20 10:31:41 · 275 阅读 · 0 评论 -
高级算法分析与设计的第一题
// Functions#include <iostream>#include <cstdlib>#include <ctime>using namespace std;int get_max_times(int a[]); // get the max of times in compare differentlyint get_min_times(int a[]); // g.原创 2021-09-08 22:28:25 · 169 阅读 · 0 评论 -
The main scheme is to get user input
// The main scheme is to get user input#include <iostream>#include <cmath>using namespace std;int main(){// int num1, num2;// cout << "Enter first number: ";// cin >> num1;// cout << "Enter second number: ";// cin &.原创 2021-09-07 22:06:00 · 45 阅读 · 0 评论 -
使用结构体数组
练习03-20-01有三个候选人,每个选民只能投票选一人,要求编写一个统计选票的程序,先后输入被选人的名字,然后输出每个人的投票结果代码如下#include<stdio.h>#include<string.h>struct Person{ char name[20]; int count;}leader[3]={"Li",0,"Zhang",0,"Sun",0};int main(){ int i,j; char leader_name[30]; f原创 2021-03-20 23:05:53 · 93 阅读 · 0 评论 -
指向指针数据的指针
练习一使用指向指针数据的指针变量输出指向的字符串样例:Follow meBASICGreat WallFORTRANComputer design--------------------------------Process exited after 0.02186 seconds with return value 0请按任意键继续. . .代码//使用指向指针数据的指针变量#include<stdio.h>int main(){ char *n原创 2021-03-19 16:59:18 · 282 阅读 · 0 评论 -
指针数组和多重指针
练习03-18-04将若干字符串按照字母顺序(由小到大输出)排序之前"Follow me","BASIC","Great Wall","FORTRAN","Computer design"排序以后:BASICComputer designFORTRANFollow meGreat Wall--------------------------------Process exited after 0.05486 seconds with return value 0请按任意键继原创 2021-03-18 22:26:53 · 130 阅读 · 0 评论 -
返回指针值的函数
练习03-18-02有三个学生,四门课的成绩,要求在用户输入用户的学生序号以后,能输出该学生的全部学习成绩。输出样例:The matrix of scores: 12.00 11.00 52.00 79.00 86.00 67.00 55.00 59.00 77.00 16.00 20.00 88.00Enter the number of the student:2The scores of NO.2 are: 77.00 16.00 20.00原创 2021-03-18 14:59:05 · 167 阅读 · 0 评论 -
用指向函数的指针变量作为函数参数
练习03-18-02//有两个整数a,b,由用户输入1,2,3.如输入1,程序给出最大值;输入2,给出最小值;输入3,给出和输出样例:Input two integer numbers:a = 34b = -2Please choose a number from 1,2,3:1a = 34b = -2max = 34--------------------------------Process exited after 36.42 seconds with return原创 2021-03-18 10:48:19 · 782 阅读 · 0 评论 -
定义和使用指向函数的指针变量
练习03-18-02输入两个整数,然后让用户选择1或2,选1时调用max函数,输出两者中的大数,选2时调用min函数,输出两者中的小数。输出样例:Input two integer numbers:a=34b=65Please choose 1 or 2: 2a = 34b = 65min = 34--------------------------------Process exited after 6.991 seconds with return value 0原创 2021-03-18 10:07:50 · 268 阅读 · 0 评论 -
用函数指针变量调用函数
练习03-18-01用函数调用求a和b中的最大值输出样例:Enter a and b3498a = 34b = 98max = 98--------------------------------Process exited after 3.787 seconds with return value 0请按任意键继续. . .方法一(通过函数名调用函数)//利用函数调用求最大值#include<stdio.h>int main(){ int ma原创 2021-03-18 09:40:15 · 663 阅读 · 0 评论 -
函数调用实现字符串的复制
输出样例:The string a =I am a good boy.the string b =I am a good student.Copy the string a to string bThe string a =I am a good boy.the string b =I am a good boy.--------------------------------Process exited after 0.05164 seconds with return value 0原创 2021-03-17 17:21:35 · 1881 阅读 · 0 评论 -
复制字符串
练习03-17-05//将字符串a复制为字符串b,然后输出字符串b输出样例:The string a :I am a student!The string b: I am a student!--------------------------------Process exited after 0.02142 seconds with return value 0请按任意键继续. . .代码1如下:#include<stdio.h>int main()原创 2021-03-17 16:18:32 · 182 阅读 · 0 评论 -
通过指针引用字符串(一)
练习03-17-05定义一个字符数组,其中存放字符串“I love China!”,输出该字符串和第八个字符。输出样例:a=I love China!I love China!a[7]=C*(a+7)=C13--------------------------------Process exited after 0.02232 seconds with return value 0请按任意键继续. . .代码(不同的输出格式)#include<stdio.h&g原创 2021-03-17 15:48:29 · 561 阅读 · 0 评论 -
用指向数组的指针作为函数参数(2)
练习03-17-03从三个学生四门成绩的二维数组中,寻找到有成绩不及格的学生,输出对应成绩:输出样例:The original score matrix: 75.00 31.00 44.00 21.00 12.00 82.00 37.00 48.00 51.00 99.00 7.00 32.00The list of failed student:The score of NO1: 75.00 31.00 44.00 21.00The score原创 2021-03-17 12:44:00 · 145 阅读 · 0 评论 -
用指向数组的指针作为函数参数
练习03-17-02输出样例:The matrix of score: 22.00 75.00 74.00 53.00 9.00 95.00 48.00 60.00 85.00 18.00 32.00 30.00The average score of whole student = 50.08The scores of first student:The score of class 1 = 22.00The score of class 2 =原创 2021-03-17 12:04:27 · 361 阅读 · 0 评论 -
用行指针变量输出二维数组中的某一个元素
练习03-17-01输出样例:The original matrix: 89 87 88 59 64 47 60 38 3 96 35 68Input x (0~2) and y(0~3)x=0y=0a[0][0]=89--------------------------------Process exited after 5.918 seconds with return value 0请按任意键继续. . .代码如下://输出二维数组中的任一行任一列元素的值原创 2021-03-17 09:02:33 · 354 阅读 · 0 评论 -
用指针变量输出二维数组各元素的值
练习03-16-04输出样例: 41 67 34 0 69 24 78 58 62 64 5 45--------------------------------Process exited after 0.02439 seconds with return value 0请按任意键继续. . .代码一://有一个数组,用指针变量输出二维数组各元素的值#include<stdio.h>#include<stdlib.h>原创 2021-03-16 23:54:40 · 2697 阅读 · 0 评论 -
二维数组的指针变量
如何理解二维数组的指针变量:例如:a[3][4]是一个二维数组,a是二维数组的数组名,按照之前一维数组的理解,它指的是整个数组的首地址,首先想到的其应该是a[0][0]的地址,其实从逻辑上来讲这是不对的,虽然数值确实一样。因为二维数组是元素为一维数组的数组,即a[3][4]指的是一个数组,其中数组元素是a[0],a[1],a[2],a[3],其都是含有五个元素的一维数组。所以*a应该指向a[0],即a中存放的是a[0]的地址,那么按照这种理解,*a的值为a[0]的值,而a[0]也是一个指针变量,它指原创 2021-03-16 21:39:39 · 558 阅读 · 0 评论 -
指针法对数组排序
练习03-16-03用指针法对10个整数按照从小到大的顺序进行排序输出样例:The original array: 17 19 12 85 54 75 5 41 50 24The sorted array: 5 12 17 19 24 41 50 54 75 85--------------------------------Process exited after 0.02482 seconds with return value 0请按任意键继续. . .代码一:原创 2021-03-16 11:44:25 · 1884 阅读 · 0 评论 -
指针变量作函数参数
练习03-16-02倒序输出一个随机数组输出样例:The arrray a: 20 33 33 32 8 29 15 9 11 29The inverted array a: 29 11 9 15 29 8 32 33 33 20--------------------------------Process exited after 0.02497 seconds with return value 0请按任意键继续. . .代码一:#include<std原创 2021-03-16 10:33:58 · 46 阅读 · 0 评论 -
数组元素逆序存放,两种解题思路
练习03-16-01输出样例:The array a : -3 0 6 -1 3 0 -3 2 -1 -1The inverted array a : -1 -1 2 -3 0 3 -1 6 0 -3--------------------------------Process exited after 0.02617 seconds with return value 0请按任意键继续. . .代码一:#include<stdio.h>#原创 2021-03-16 00:27:43 · 577 阅读 · 0 评论 -
2021-03-15
练习 03-15-04//用指针型变量输出整型数组a的10个元素a[0] =4a[1] =6a[2] =8a[3] =48The original array:a[1] = 4 a[2] = 6 a[3] = 8 a[4] = 48--------------------------------Process exited after 6.996 seconds with return value 0请按任意键继续. . .原创 2021-03-15 18:12:23 · 47 阅读 · 0 评论 -
2021-03-15
练习 输出数组元素:样例:The original a: 4 13 12 1 11 5 14 2 7 11--------------------------------Process exited after 0.0209 seconds with return value 0请按任意键继续. . .方法一(角标法)://一个整型数组a,要求输出数组中的全部元素;#include<stdio.h>#include<time.h>#inc原创 2021-03-15 17:47:41 · 42 阅读 · 0 评论 -
2021-03-15
练习指针变量作为函数参数//输入三个整数:a,b,c要求按由大到小的顺序将他们输出输出样例:Input three integer numbers:34 76 12The original number a=34,b=76,c=12The sorted numbers:76,34,12--------------------------------Process exited after 5.684 seconds with return value 0请按任意键继续. . .原创 2021-03-15 17:00:17 · 74 阅读 · 0 评论 -
2021-03-15
练习03-15-01//输入a和b两个整数,按先大后小的顺序输出a和b。方法一:(借用指针输出对应的最大值和最小值)#include<stdio.h>int main(){ int a,b; printf("Input two integer numbers:\n"); scanf("%d%d",&a,&b); int *pointer_a,*pointer_b,*pointer; pointer_a=&a,pointer_b=&b;原创 2021-03-15 16:28:54 · 65 阅读 · 0 评论 -
2021-03-11
练习03-11-01用一个字符串,内有若干个字符,现在输入一个字符,要求程序将字符串中该字符删去。输出样例://样例一:This is a C program.Input the character you will delete..This is a C program//样例二:This a C programInput the character you will delete.aThis C progrm代码如下://有一个字符串,内有若干个字符,现输入.原创 2021-03-11 11:40:48 · 126 阅读 · 0 评论 -
2021-03-08
练习 03-08-01//给定b的值,出入a和m,求a*b和a的m次方输出样例:please input two integers:4 6a*b = 16The power a of m = 4096--------------------------------Process exited after 2.949 seconds with return value 0请按任意键继续. . .代码如下://给定b的值,出入a和m,求a*b和a的m次方#include&原创 2021-03-08 10:51:05 · 139 阅读 · 0 评论 -
2021-03-07
练习 03-07-01求三个整数中的最大值方法一://调用函数求,三个函数中的最大值#include<stdio.h>int main(){ extern int A,B,C; int i; printf("Enter three integer numbers:\n"); scanf("%d%d%d",&A,&B,&C); int max(); printf("The max = %d",max()); return 0; } i原创 2021-03-08 10:38:46 · 67 阅读 · 0 评论 -
2021-03-06
练习 03-06-01有一个一维数组,存放十个学生的成绩,每一个函数,当主函数调用此函数时,能求出平均分、最低分和最高分。输出样例:The original array: 118 70 123 103 18 66 76 78 133 141The max = 141;The min = 18;The average = 92.60--------------------------------Process exited after 0.02273 s原创 2021-03-06 07:56:22 · 74 阅读 · 0 评论 -
2021-03-05
练习 03-05-01有一个3*4的矩阵,利用max_value函数求其中的最大值;方法一(简单版):输出样例:The max value of this matrix = 94--------------------------------Process exited after 0.02103 seconds with return value 0请按任意键继续. . .代码如下:#include<stdio.h>int main(){ int ma原创 2021-03-05 21:35:14 · 61 阅读 · 0 评论 -
2021-03-04
练习 03-04-02//用选择法对数组中10个整数按照由小到大的顺序排序输出样例:array A = 8 1 4 3 7 9 1 4 7 8The sorted array A = 1 1 3 4 4 7 7 8 8 9代码如下:#include<stdio.h>#include<stdlib.h>#include<tim原创 2021-03-04 22:59:45 · 62 阅读 · 1 评论 -
2021-03-04
练习 02-04-01 (数组名作为函数参数)题目要求:两个班级,分别有35名和30名学生,调用一个average函数,分别求出这两个班的学生的平均成绩输出样例:array A: 43 41 70 14 76 3 66 33 28 96 46 53 77 9 25 98 39 48 76 87 86 59 7 31 20 18 0 19 45 45 .原创 2021-03-04 19:16:01 · 1622 阅读 · 2 评论 -
2021-03-03
练习03-03-04 数组名作函数参数NOTICE:用数组元素作为实参时,向形参变量传递的是数组元素的值,而用数组名作为函数实参,向形参(数组名或指针变量)传递的是数组元素的首地址。题目要求:有一个一维数组score,内放10个学生成绩,求平均成绩。输出样例:The original array: 104 56 141 53 73 84 129 72 85 87average score = 88.400002------------------原创 2021-03-03 21:59:06 · 59 阅读 · 2 评论 -
2021-03-03
练习03-03-04 数组元素作函数参数要求:输入10个数,要求输出其中值最大的元素和该数是第几个数输出样例:The array is: -5 -1 4 -2 3 1 -5 3 4 -3The max = 4, its position = 3--------------------------------代码如下:#include<stdio.h>#include<stdlib.h>#include<time.h>int m原创 2021-03-03 21:39:08 · 48 阅读 · 1 评论 -
2021-03-03
练习 03-03-03 汉诺(Hanoi)塔问题问题描述:古代有一个梵塔,塔内有三个座A,B,C,开始的时候,A座上有64个盘子,盘子大小不等,大的在下面,小的在上面。有一个老和尚想要把64个盘子从A座位移动到C座位上,但是规定每次只允许移动一个盘子,且在移动的过程中,在三个座位上都始终保持大盘在下,小盘在上。在移动的过程中可以利用B座。要求编写程序输出移动盘子的步骤。分析:将n个盘子从A座移动到C座上可以分解为以下三个步骤:(1)将A上n-1个盘借助C移动到B座位上,(2)将A座位上的原创 2021-03-03 19:05:29 · 66 阅读 · 1 评论 -
2021-03-03
练习03-03-02(函数的递归调用)(回溯和递归)有五个学生坐在一起,问第五个学生的年龄,他说比第4个学生大2岁,。问第四个学生,他说比第三个学生大2岁。问第三个学生,又说他比第二个学生大2岁。问第2个学生,他所比第一个学生大两岁。最后问第一个学生,他说是10岁。请问第五个学生的年纪。数学公式表示:输出样例:NO.5 age:18--------------------------------Process exited after 0.02141 seconds with原创 2021-03-03 12:15:03 · 76 阅读 · 0 评论 -
2021-03-03
练习 03-03-01输入四个整数,找出其中最大的数。输出样例:enter four numbers:12 34 -4 98max = 98please enter four numbers:58 98 -9 0max = 98--------------------------------Process exited after 11.42 seconds with return value 0请按任意键继续. . .方法一:“打擂台算法”#includ.原创 2021-03-03 10:22:11 · 55 阅读 · 0 评论 -
2021-03-02
练习 03-02-06使用模块化程序设计思路,用辗转相除法求两个数的Greatest Common Divisor.please enter two integers:40 8The greatest common divisor is:8--------------------------------Process exited after 6.299 seconds with return value 0请按任意键继续. . .代码如下://greatest common原创 2021-03-02 19:02:13 · 45 阅读 · 0 评论 -
2021-03-02
练习 03-02-05函数调用的第一个例子:********************How do you do?********************--------------------------------Process exited after 0.05986 seconds with return value 0请按任意键继续. . .代码:#include<stdio.h>int main(){ void print_star(int n)原创 2021-03-02 12:00:35 · 60 阅读 · 0 评论 -
2021-03-02
练习 03-02-04编写一个程序,将字符数组s2中的全部字符复制到字符数组s1中。输出样例:s1 = I am a student.--------------------------------Process exited after 0.0559 seconds with return value 0请按任意键继续. . .方法1:#include<stdio.h>#include<string.h>int main(){ char s2[原创 2021-03-02 11:50:28 · 95 阅读 · 0 评论