c语言中对象式宏(全局变量)

 

1、

#include <stdio.h>

#define XXX 3

int main(void)
{
    int i;
    int a[XXX];
    int sum = 0;
    
    puts("please input the scores of the students.");
    for (i = 0; i < XXX; i++)
    {
        printf("%dst = ", i + 1);
        scanf("%d", &a[i]);
        sum += a[i];
    }
    
    printf("sum = %5d\n", sum);
    printf("mean = %5.1f\n", (double)sum/XXX);
    return 0;
}

 

 

2、

#include <stdio.h>

#define XXX 5

int main(void)
{
    int i;
    int a[XXX];
    int sum = 0;
    
    puts("please input the scores of the students.");
    for (i = 0; i < XXX; i++)
    {
        printf("%dst = ", i + 1);
        scanf("%d", &a[i]);
        sum += a[i];
    }
    
    printf("sum = %5d\n", sum);
    printf("mean = %5.1f\n", (double)sum/XXX);
    return 0;
}

 

posted @ 2021-02-03 22:31  小鲨鱼2018  阅读(336)  评论(0编辑  收藏  举报