
#include#include #include using namespace std; // 判断一个数是否为素数 bool isPrime(int num, int value) { if (value == num - 1 || num == 2 || num == 1) return true; return (num % value == 0) ? false : isPrime(num, ++value); } void test_sushu() { cout << "please input a number:"; int num; cin >> num; if (isPrime(num, 2)) cout << "it is a prime" << endl; else cout << "it isn't a prime" << endl; } // 字符串分割练习改写 void split(string str, int i, char ch) { if(i==str.length()-1) return; else { if(str.at(i)!=ch) cout< array[i]) { index = i + 1;value = array[i];} getMin(array, i + 1, size, index, value); } } int main() { cout << "-------------------begin--------------------------n" << endl; test_sushu(); cout << "-------------------begin--------------------------n" << endl; int array[] = {10, 2, 6, 1, 4, 5, 7, 1, 9, 14}; getMin(array, 0, 10, 0, array[0]); cout << "-------------------begin--------------------------n" << endl; string str = "Nice to meet you !"; split(str,0,' '); cout << "n--------------------end----------------------------" << endl; return 0; }
运行效果如下:
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)