This program outputs 1. I could not understand how it outputs 1 as the for loop will fail at a[2][3] which contains the value 12. So 12 will get assigned to k and the output will have to be 12.
#include<stdio.h>
int main()
{
int a[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};
int i,j,k=99;
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
if(a[i][j]<k)
{
k=a[i][j];
printf("%d\n",k);
}
}
}
printf("Res:%d\n",k);
return 0;
}
The first time through the loop the if is evaluated as a[0][0] < k which is 1 < 99 which is true.
The second time through he loop if the if is a[1][0] < k which is 2 < 1 which evaluates as false thus the value of k is not updated
k is never reassigned another value, thus at the end k=1.