华师专硕上机
George&Rita
星光不负赶路人!
展开
-
C++实现经典排序算法(超详细注释)
因为是在准备考研的复试上机,没有太多的时间整理出完善的知识点。因此,这里只给出每种排序算法的具体实现,如有不周到的地方,请见谅,谢谢!一、冒泡排序算法#include <iostream>using namespace std;//冒泡排序算法void bubbleSort(int num[], int n) { for (int i = 0; i < n - 1; i++) { //外层循环,只需要比较n-1次 bool flag = false; //标志位,判原创 2021-02-22 10:56:40 · 449 阅读 · 0 评论 -
华南师大19级软件学院专硕上机题
一、 n的阶乘、两种方法实现、for循环或递归#include <iostream>using namespace std;//方法一:for循环int method1(int n) { int k = 1; int answer = 1; for (; k <= n; k++) { answer *= k; } return answer;}//方法二:递归int method2(int n) { if (n == 1) { return 1; }原创 2021-02-17 09:46:28 · 747 阅读 · 0 评论 -
华南师大19级计算机学院专硕上机题
一、 编程计算1/1!-1/3!+1/5!-…+(-1)(n+1)/(2n-1)!#include <iostream>using namespace std;int main() { int n; //输入n cin >> n; int t = 1; double num = 1; //定义变量 double sum = 0; double temp = num; while (n>0) { sum += 1 / temp * t原创 2021-02-14 11:58:06 · 1701 阅读 · 1 评论 -
华南师大18级计算机学院专硕上机题
一、 a到z的字母用ASCII码表示,显示出来#include <iostream>using namespace std;int main(){ for (char c = 'a'; c <= 'z'; c++) { cout << c << ":" << (int)c<<endl; }}二、 求一元二次方程的根#include <iostream>#include <cmath>usin原创 2021-02-10 11:52:37 · 490 阅读 · 0 评论 -
华南师大17级计算机学院专硕上机题
一、输入一个数字,为其高,一个符号*,输出该符号组成的平行四边形形状。#include <iostream>using namespace std;int main() { int num; cin >> num; //输入数字 for (int i = 1; i < num+1; i++) { //打印num行 for (int j = 1; j < i; j++) { //打印空格 cout << " "; }原创 2021-02-09 15:28:53 · 607 阅读 · 0 评论 -
华南师大14级计算机学院专硕上机题
一、判断输入的数是否为素数#include <iostream>#include <cmath>using namespace std;bool isPrime(int num) { if (num == 1) { //1不是素数 return false; } for (int i = 2; i < sqrt(num); i++) { if (num % i == 0) { //能整除则不是素数 return false; }原创 2021-02-08 16:27:35 · 308 阅读 · 0 评论 -
华南师大13级计算机学院专硕上机题
一、编写一个程序,给出方程3x+2y-7z=5(其中,0≤x,y,z≤10),求满足方程的所有x,y和z,输出之。#include <iostream>using namespace std;int main() { int x, y, z; int n = 0; for (x = 0; x <= 10; x++) { for (y = 0; y <= 10; y++) { for (z = 0; z <= 10; z++) { if (3 *原创 2021-02-07 11:15:27 · 369 阅读 · 0 评论