数组最大的数
有个数组a(10),如果他的某一位比他前面所有的数都大就输出该数字,求教大婶怎么编程。。#include <stdio.h> #include<limits.h> #define SIZE(s) sizeof(s)/sizeof(*s) int main( void ) { int a[]= {2,1,4,3,6,5,8,7,10,9}; int max=INT_MIN; size_t i=0; for (i=0; i!=SIZE(a); ++i) printf(a[i]>max?" %-4d":"",max=a[i]); puts(""); return 0; }
[此贴子已经被作者于2018-1-10 11:42编辑过]
#include <stdio.h> #include<limits.h> #define SIZE(s) sizeof(s)/sizeof(*s) int main( void ) { const int a[]= {2,1,4,3,6,5,8,7,10,9}; int max=INT_MIN; size_t i=0; for (i=0; i!=SIZE(a); ++i) a[i]>max&&printf(" %-4d",max=a[i]); puts(""); return 0; }
#include <stdio.h> #include<limits.h> #define SIZE(s) sizeof(s)/sizeof(*s) int main( void ) { const int a[]= {2,1,4,3,6,5,8,7,10,9,13,15,10}; int max=INT_MIN; size_t i=0; #define __MAX(a,b) ((a)>(b)?(a):(b)) for (i=0; i!=SIZE(a); ++i) printf("\0%-4d"+(a[i]>max),max=__MAX(max,a[i])); puts(""); #undef __MAX return 0; }
[此贴子已经被作者于2018-1-10 19:57编辑过]