正在加载图片...
The C Programming language Chapter 7 Arrays ☆ Examples #include <stdio h Expl: reads 10 integers#define SIZe 10 main i int x[],i, max, min STEPS printf("Enter 10 integers: n") 1.Input: use for to for( i=0 i<SIZE; i++) 2. Process i printf("%/od: ,i+1) (a)let max-min scanf("%d", &x[) (b)Compare x[il if max x[i], max-min=xIO if minx[], for(i=1; K<SIZE; i++) Output: maxIm if(max<x[i]) max-x[i] if(min>xi] min=x[i] printf("Maximum value is %d n", max printf("Minimum value is %/odn",min)The C Programming Language Chapter 7 Arrays ❖ Examples Exp1: reads 10 integers and stores in array, find the max , min STEPS: 1. Input :use for to read 10 integers; 2. Process : (a) let max=min= x[0] (b) Compare x[i] with max,min (loops) if max<x[i], let max=x[i] if min>x[i], let min=x[i] 3. Output :max和min #include <stdio.h> #define SIZE 10 main() { int x[SIZE],i,max,min; printf("Enter 10 integers:\n"); for(i=0;i<SIZE;i++) { printf("%d:",i+1); scanf("%d",&x[i]); } max=min=x[0]; for(i=1;i<SIZE;i++) { if(max<x[i]) max=x[i]; if(min>x[i]) min=x[i]; } printf("Maximum value is %d\n",max); printf("Minimum value is %d\n",min); }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有