在外部变量中查找最大数字

时间:2014-08-09 05:07:27

标签: c++ arrays numbers

大家好我想用外部变量构建一个程序,但是当程序调试时我很难显示数字。我的程序是显示每列中最大的数字。例如,88 98 88 98中的最大数字和67 34 67 34中的最大数字,依此类推。你能帮助我吗?

第一来源档案

#include<stdio.h>
void main(void)
{
    extern int transitTime[];
    int i;
    int number,largest;
    largest=0;
    for(i=0;i<11;i++)
    {
    scanf_s("%d",&number);
    if(number>largest)largest=number;
    }
    printf("Largest=%d\n",largest);
}

第二来源档案

int transitTime[] =
{
    88, 67, 90, 12, 34, 65, 100, 78, 56, 77, 85, //bus 8
    98, 34, 67, 98, 67, 45, 67, 23, 45, 67, 89, //bus15
    88, 67, 90, 12, 34, 65, 100, 78, 56, 77, 85, //22
    98, 34, 67, 98, 67, 45, 67, 23, 45, 67, 89, //23
};

1 个答案:

答案 0 :(得分:0)

#include<stdio.h>
void main(void)
{
    //extern 
    int transitTime[] ={
    88, 67, 90, 12, 34, 65, 100, 78, 56, 77, 85, //bus 8
    98, 34, 67, 98, 67, 45, 67, 23, 45, 67, 89, //bus15
    88, 67, 90, 12, 34, 65, 100, 78, 56, 77, 85, //22
    98, 34, 67, 98, 67, 45, 67, 23, 45, 67, 89, //23
    };
    int i,j;
    int largest;

    for(i=0;i<11;i++)
    {
    largest=0;
    printf("larger among ");

    for(j=0;j<4;j++)
    {
    printf("%d ",transitTime[i+j*11]);
    if(transitTime[i+j*11]>largest)largest=transitTime[i+j*11];
    }

    printf("is %d\n",largest);
    }
}