1.

#include <iostream> 
using namespace std; 
void inverse(int *p, int n){
    int exp = 0;
    int *q = n + p - 1;
    while(p < q){
        exp = *p;
        *p = *q;
        *q = exp;
        p++;
        q--;
    }
}
int main(){
    int n = 10, i;
    cout << "please input the total number: " << endl;
    cin >> n;
    int *a = new int[n];
    cout << "please input the number with the length of n: " << endl;
    for (i = 0; i < n;i++){
        cin >> a[i];
    }
    inverse(a, n);
    cout << "the inverse number is: " << endl;
    for (i = 0;i < n;i++){
        cout << a[i] << " ";
    }
    cout <<endl;
    return 0;
}
-------
input: 10
1 2 3 4 5 6 7 8 9 10
output:
10 9 8 7 6 5 4 3 2 1

#include <iostream> 
using namespace std; 
void num_statics(char *p, int n){
    int i;
    int flag_1 = 0, flag_2 = 0, flag_3 = 0, flag_4 = 0, flag_5 = 0;
    for (i = 0; i < n;i++){
        if(*p>='A' && *p<='Z'){
            flag_1++;
            *p++;
        }
        else if(*p >='a'&& *p<='z'){
            flag_2++;
            *p++;
        }
        else if (*p == ' '){
            flag_3++;
            *p++;
        }
        else if (*p >= '0' && *p <= '9'){
            flag_4++;
            *p++;
        }
        else{
            flag_5++;
            *p++;
        }
    }
    cout << "大写字母数:" << flag_1 << endl;
    cout << "小写字母数:" << flag_2 << endl;
    cout << "空格数:" << flag_3 << endl;
    cout << "数字数:" << flag_4 << endl;
    cout << "其他字符数:" << flag_5 << endl;
}

int main(){
    char a[20];
    cout << "the input string can't over 20! please input the string: " << endl;
    cin.getline(a, 20);
    char *p = a;
    int n = strlen(a);
    num_statics(a, n);
    return 0;
}
----
input: We Are Fa12@()
output:
We Are Fa12
小写字母数:3
大写字母数:4
空格数:2
数字数:2
其他字符数:3
#include <iostream> 
using namespace std; 
void num_statics(char *p, int n){
    int i;
    int flag_1 = 0, flag_2 = 0, flag_3 = 0, flag_4 = 0, flag_5 = 0;
    while(*p){
        if(*p>='A' && *p<='Z'){
            flag_1++;
        }
        else if(*p >='a'&& *p<='z'){
            flag_2++;
        }
        else if (*p == ' '){
            flag_3++;
        }
        else if (*p >= '0' && *p <= '9'){
            flag_4++;
        }
        else{
            flag_5++;
        }
        p++;
    }
    cout << "大写字母数:" << flag_1 << endl;
    cout << "小写字母数:" << flag_2 << endl;
    cout << "空格数:" << flag_3 << endl;
    cout << "数字数:" << flag_4 << endl;
    cout << "其他字符数:" << flag_5 << endl;
}

int main(){
    char a[20];
    cout << "the input string can't over 20! please input the string: " << endl;
    cin.getline(a, 20);
    char *p = a;
    int n = strlen(a);
    num_statics(a, n);
    return 0;
}
#include <iostream>
#include <string> 
using namespace std;
void insert(char *exp1, char *exp2, int n){
    strcpy(exp1+n,strcat(exp2, exp1+n));
    cout << exp1;
}
int main(){
    int i, n;
    char a[30];
    char b[30];
    cout << "the input string can't over 20! please input the string: " << endl;
    cin.getline(a, 30);
    int n1 = strlen(a);
    cout << "the string is: " <<endl;
    for (i = 0; i < n1;i++){
        cout << i+1 << a[i] << " ";
    }
    cout <<endl << "please input insert string and number!" << endl;
    cout << "the insert string: ";
    cin.getline(b, 30);
    cout << "the insert  number is: ";
    cin >> n;
    int n2 = strlen(b);
    insert(a, b, n);
    return 0;
}
Last modification:December 10th, 2020 at 10:56 pm
小编饿得写不动了,请给小编加鸡腿