C++求最大公约数,检查回文,输出素数

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
        
    int number1;
    int number2;
    
    cout<<"第一个数"<<endl;
    cin>>number1;
    cout<<"第二个数"<<endl;
    cin>>number2;
    
    int k = 1;
    int result;
    while(k<number1 && k<number2){
        if (number1%k==0&&number2%k==0) {
            result = k;
        }
        k++;
    }
    
    cout<<number1<<"和"<<number2<<"最大公约数为"<<result<<endl;
    return 0;
}
#include <iostream>
#include <string>
using namespace::std;
int main(int argc, const char * argv[]) {
    // insert code here...
    
    string chuan;
    cout<<"请输入一串字符串:"<<endl;
    getline(cin, chuan);
    
    int low = 0;
    int high =chuan.length()-1;
    
    bool judge = 1;
    while (low<high) {
        
        if (chuan[low]!=chuan[high]) {
            judge = 0;
            break;
        }
        low++;
        high--;
    }
    if (judge == 1) {
        cout<<chuan<<"是一个回文串"<<endl;
    }
    else
        cout<<chuan<<"不是一个回文串"<<endl;
    return 0;
}
#include <iostream>
using namespace::std;
int main(int argc, const char * argv[]) {
    // insert code here...
    
    int number;
    cout<<"请输入一个数";
    cin>>number;
    int count = 0;
        for(int j=2 ; j<number;j++){
            int k = 0;
            for (int i=2; i<=j/2; i++) {
                if (j%i==0) {
                    k=1;
                    break;
                }
            }
            if (k==0) {
                cout<<j<<" ";
                count ++;
            }
            if (count == 5) {
                cout<<"\n";
                count = 0;
            }
            k = 0;
        }
        cout<<"\n";
}

上一篇:21天好习惯第一期—7


下一篇:C++——基础知识入门