5.1
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
int mymax(int *p,int n){
int max;
for(max=p[(--n)--];n>=0;n--)
if(max<p[n]) max=p[n];
return max;
}
int main(void){
int a[10],i;
printf("Please input 10 integers...\n");
for(i=0;i<10;scanf("%d",a+i++));
printf("The MAX is %d\n",mymax(a,10));
return 0;
}
5.2
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
int mygcd(int x,int y){
int r;
while(y){
r=x%y;
x=y;
y=r;
}
return x;
}
int mylcm(int a,int b){
return a/mygcd(a,b)*b;
}
int main(void){
int a,b;
while(1){
printf("Please input a & b(int a,b>0 0 end)...\n");
if(scanf("%d%d",&a,&b),a>0 && b>0){
printf("The GCD is %d\n",mygcd(a,b));
printf("The LCM is %d\n\n",mylcm(a,b));
}
else if(a==0 || b==0)
break;
else printf("Error, redo: ");
}
return 0;
}
本回答被网友采纳