calculating min and max of 2-D array in c

Posted by m2010 on Stack Overflow See other posts from Stack Overflow or by m2010
Published on 2010-05-18T06:27:40Z Indexed on 2010/05/18 6:40 UTC
Read the original article Hit count: 345

Filed under:
|
|

This program to calculate sum,min and max of array elements Max value is the problem, it is always not true.

void main(void) { int degree[3][2]; int min_max[][]; int Max=min_max[0][0]; int Min=min_max[0][0]; int i,j; int sum=0;

clrscr();
for(i=0;i<3;i++)
{
    for(j=0;j<2;j++)
    {
        printf("\n enter degree of student no. %d in subject %d:",i+1,j+1);
        scanf("%d",&degree[i][j]);
    }

}


for(i=0;i<3;i++)
{
    for(j=0;j<2;j++)
    {
        printf("\n Student no. %d degree in subject no. %d is %d",i+1,j+1,degree[i][j]);

    }

}


for(i=0;i<3;i++)
{
    sum=0;
    for(j=0;j<2;j++)
    {
        sum+=degree[i][j];

    }
    printf("\n sum of degrees of student no. %d is %d",i+1,sum);
    min_max[i][j]=sum;
    if(min_max[i][j] <Min)
    {
        Min=min_max[i][j];
    }
    else if(min_max[i][j]>Max)
    {
        Max=min_max[i][j];
    }




}
printf("\nThe minimum sum of degrees of student no. %d is %d",i,Min);
printf("\nThe maximum sum of degrees of student no. %d is %d",i,Max);
getch();

}

© Stack Overflow or respective owner

Related posts about c

    Related posts about arrays