1.使用牛顿迭代法求方程
牛顿迭代法的公式: xn+1 = xn-f(x1)/f’(x1)
#include <iostream>#include <math.h>using namespace std;int main(){// 牛顿迭代法的公式: xn+1 = xn-f(x1)/f'(x1)// double sqrt(double x); x^2double x0, x1, f, f1;x1 = 1.5;do{x0 = x1;f = 2 * x0 * x0 * x0 - 4 * x0 * x0 + 3 * x0 - 6;f1 = 6 * x0 * x0 - 8 * x0 + 3;x1 = x0 - f / f1;} while (fabs(x0 - x1) >= 1e-6);cout << "结果为:" << x1 << endl;system("pause");return 0;}

2.实现字符串拷贝功能
#include <iostream>#include <string>using namespace std;//实现字符串的拷贝功能//1.stringvoid scopy(string &a, string &b){a = b;}//2字符数组void scopy(char *a, char *b){while (*b != '\0'){*a = *b;a++;b++;}*a = '\0';}
3.编写一个函数检测输入的字符是大写还是小写或者不是26个英文字母
#include <iostream>using namespace std;//编写一个函数检测输入的字符是大写还是小写或者不是26个英文字母void identify(char s){if (s > 'a' && s < 'z'){cout << "小写" << endl;}else if (s > 'A' && s < 'Z'){cout << "大写" << endl;}else if (s > '0' && s < '9'){cout << "数字" << endl;}else{cout << "特殊字符" << endl;}}int main(){char c;do{cin >> c;identify(c);} while (c != 'q');system("pause");return 0;}
(补充)统计字符串中大小写字母和数字的个数
#include <iostream>using namespace std;void identify(char s, int &a, int &b, int &c, int &d){if (s > 'a' && s < 'z'){a++;}else if (s > 'A' && s < 'Z'){b++;}else if (s > '0' && s < '9'){c++;}else{d++;}}void count(char *s){int a, b, c, d;a = b = c = d = 0;while (*s != '\0'){identify(*s, a, b, c, d);s++;}cout << "小写:" << a << endl;cout << "大写:" << b << endl;cout << "数字:" << c << endl;cout << "特殊字符:" << d << endl;}int main(){char a[] = "hh21ERRR2dd}}{}{fdf}";count(a);system("pause");return 0;}

4.密码编译
A->Z a->z;B->Y b->Y
只改变字母,数字不发生改变第i个字母变成
