#include<stdio.h> #include<dos.h> #include<stdlib.h> #include<string.h>
#define MAX 100 /*设置最大可求的整数数目*/ #define N atoi(argv[1]) /*将命令行得到的字符转化为整型值*/ #define max(a,b) (a<b)?b:a /*定义求两个数的最大值宏*/
void main(int argc,char *argv[]) { int i,j; int s[MAX]; if(argc<2){ /*若没有参数*/ printf("error: No command line./n"); printf("You must input the length that you want./n"); printf("example: max 5/n"); exit(1); } if(argc>3){ /*若参数超过数目*/ printf("error: Too many paterners!/n"); printf("The exact style: max N/n"); exit(1); } if(argc==3&&!strcmp(argv[2],"sound")){/*如果用户写了可选参数sound*/ sound(1000);delay(3000);nosound(); sound(800);delay(3000);nosound(); }
printf("Please input numbers:/n"); for(i=0;i<N;i++) scanf("%d",&s[i]); for(j=0;j<N;j++) s[j+1]=max(s[j],s[j+1]); printf("The max number is %d./n",s[N-1]); printf("/nEND"); }
|