RSS
 

Posts Tagged ‘源码’

指针-数组 之 寻找最小数字

24 May

刚刚写成功了一个,受到了很多 CPL 那个书的启发。源码大家可以看下面:

#include"stdio.h"
#define N 5

main()
{
	int i,j=0,a[N];
	int *p=&a[0];

	printf("Input %d numbers:\n",N);

	for (i = 0; i < N; i++){
		scanf("%d",&a[i]);
	}
	for (i = 0; i < N; i++){
		if (*(p+i) < *p){
			*p = *(p+i);
			j = i+1;
		}
	}
	printf("the smallest number is: %d, No.%d\n",*p,j);
}

大家在这里查看 P.S:coolcode 插件不认 c 语言,所以缩进没有了。大家看刚才那个链接吧,那样会好点。

我的一个问题是,我想把中间那两个for给剩下一个,怎么作呢?貌似直接接上不成……迷惑中,觅达人~

update Jaykenduke 童鞋先抓了一只虫~
update @ May-26-2008 新版本的程序已经更新,大家看这里

 
5 Comments

Posted in web