1.

#include <iostream>
#include <string.h>
using namespace std;

#define MIN(x, y) (x)<(y) ? (x):(y)

int main(){
    int i = 10, j = 15, k;
    k = 10*MIN(i, j);
    cout <<k <<endl;
    return 0;
}

2.

#include <iostream>
#include <string.h>
using namespace std;

#define PLUS(X, Y) X+Y 

int main(){
    int x = 1, y = 2, z = 3, sum;
    sum = PLUS(x+y, z)*PLUS(y, z);
    cout <<"SUM = " <<sum <<endl;
    return 0;
}

3.

#include <iostream>
#include <string.h>
using namespace std;

#define N 5
#define M N+1
#define f(x) (x*M)

int main(){
    int i1, i2;
    i1 = f(2);
    i2 = f(1+1);
    cout <<i1 <<'\t' <<i2 <<endl;
    return 0;
}

4.

#include <iostream>
using namespace std;

#define MAX(a, b) (a>b? a:b) +1

int main(){
    int i = 6, j = 8, k;
    k = MAX(i, j);
    cout <<k <<endl;
    return 0;
}

5.

#include <iostream>
using namespace std;

int x = 1;
int f(int);
int main(){
    cout <<f(x);
    return 0;
}

#define x 2
int f(int y){
    return x+y;
}

6.

#include <iostream>
using namespace std;

int main(){
    int s[12] = {1, 2, 3, 4, 4, 3, 2, 1, 1, 1, 2, 3}, c[5] = {0}, i;
    for(i = 0; i < 12;i++)     c[s[i]]++;
    for(i = 1;i < 5;i++)   cout <<c[i];
    cout <<endl;
    return 0;
}

7.

#include <iostream>
#include <string>

using namespace std;

int main(){
    char st[20] = "hello\0\t\'\\";
    cout <<strlen(st) <<endl;
    return 0;
}

8.

#include <iostream>
#include <string>

using namespace std;

int main(){
    int a[] = {2,3,5,4}, i;
    for(i = 0; i < 4; i++){
        switch(i%2){
        case 0: switch(a[i]%2){
                    case 0:  a[1]++; break;
                    case 1: a[i]--;
                }break;
        case 1:a[i] = 0;
        }
    for(i = 0; i < 4;i++)  cout <<a[i] <<'\t';
    }
    return 0;
}

9.

#include <iostream>
#include <string>

using namespace std;

int main(){
    int a[2][3], i, j, n = 1;
    for(i = 0;i < 2;i++)
        for(j = 0; j < 3;j++)    a[i][j] = n++;
        for(i = 0;i < 2;i++){
        for(j = 0;j < 3;j++)    cout <<a[i][j] <<'\t';
        cout <<endl;
        }
    return 0;
}
Last modification:November 17th, 2020 at 04:52 pm
小编饿得写不动了,请给小编加鸡腿