看到一篇很不错的c语言基本知识总结,学而无涯啊。
C语言基础知识总结大全
求最值的程序贴上,慢慢积累。向大牛们学习!
/求最大值,返回下标max_num
unsigned long buf[10] =[10, 0, 1, 2, 3, 4 , 5, 7, 9, 0];
unsigned char find_max_num(unsigned long *buf , int num)
{
unsigned char i;
unsigned long max = 0;
unsigned char max_num = 0;
max = buf[0];
for(i = 0; i < num; i++)
{
if(max < buf[i])
{
max = buf[i];
max_num = i;
}
}
return max_num;
}
//求最小值,返回下标min_num
unsigned char find_min_num(unsigned long *buf , int num)
{
unsigned char i;
unsigned long min =0;
unsigned char min_num = 0;
min = buf[0];
for(i = 0; i < num; i++)
{
if( buf[i] < min)
{
min = buf[i];
min_num = i;
}
}
return min_num;
}
优秀是最好的自律!