1,求一个3x4的矩阵,要求输出鞍点(行列均为最大的值)?
#include <stdio.h>
int main(int argc, const char *argv[])
{
int i,j,temp=0;
int a[3][4] = {
{123,94,-10,218},
{333,9,10,-83},
{45,16,44,-99}
};
for( i=0 ; i<3 ; i++)
{
for( j=0 ;j<3 ;j++)
{
if(a[i][j] > a[i][j+1])
{
temp = a[i][j];
a[i][j] = a[i][j+1];
a[i][j+1] = temp;
}
}
for(j = i;j < 2;j++)
{
if(a[j][3] > a[j+1][0])
{
temp = a[j][3];
a[j][3] = a[j+1][0];
a[j+1][0] = temp;
}
}
}
printf("anshu = %d\n",a[2][3]);
return 0;
}
2,求一个3x4的矩阵,要求输出(全矩阵最大的值)输出其行列号(行列不改变)?
#include <stdio.h>
int main(int argc, const char *argv[])
{
int i,j,temp=0,m=0,n=0;
int a[3][4] = {
{123,94,-10,218},
{333,9,10,-83},
{45,16,44,-99}
};
for( i=0 ; i<3 ; i++)
{
for( j=0 ;j<4 ;j++)
{
if(temp < a[i][j])
{
temp = a[i][j];
m = i;
n = j;
}
}
}
printf("anshu = %d hang = %d lie = %d/n",a[m][n],m,n);
return 0;
}
3,写出一个函数,统计int类型的值中有多少位为1(二进制1)?
#include <stdio.h>
int main(int argc, const char *argv[])
{
int a=0,len=0;
printf("please input one number:\t");
scanf("%d",&a);
while(a != 0)
{
if((a%10) == 1)
{
len++;
a = a/10;
}
//
else if (a == 0)
//
{
//
break;
//
}
else
{
a = a/10;
}
}
printf("1 de shu liang = %d\n",len);
return 0;
}