View Code of Problem 59

#include

void main(){

int a,b,n1,n2,t;

while(true)

{

printf("任意输入两个正整数:\n");

scanf("%d%d",&n1,&n2);

if(n1

{

t = n1;

n1 = n2;

n2 = t;

}

a = n1;

b = n2;

while(b!=0){   /*利用辗除法,直到b为0为止*/

t = a%b;

a=b;

b=t;

}

printf("最大公约数为:%d\n",a);

printf("最小公倍数为:%d\n\n",n1*n2/a);

}}

/*
Main.c:1:9: error: #include expects "FILENAME" or <FILENAME>
 #include
         ^
Main.c:3:6: warning: return type of 'main' is not 'int' [-Wmain]
 void main(){
      ^
Main.c: In function 'main':
Main.c:7:7: error: 'true' undeclared (first use in this function)
 while(true)
       ^
Main.c:7:7: note: each undeclared identifier is reported only once for each function it appears in
Main.c:11:1: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
 printf("任意输入两个正整数:\n");
 ^
Main.c:11:1: warning: incompatible implicit declaration of built-in function 'printf'
Main.c:13:1: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
 scanf("%d%d",&n1,&n2);
 ^
Main.c:13:1: warning: incompatible implicit declaration of built-in function 'scanf'
Main.c:17:1: error: expected ')' before '{' token
 {
 ^
Main.c:31:1: error: stray '\302' in program
 while(b!=0){   /*利用辗除法,直到b为0为止*/
 ^
Main.c:31:1: error: stray '\240' in program
Main.c:45:1: error: expected expression before '}' token
 }}
 ^
Main.c:5:15: warning: unused variable 't' [-Wunused-variable]
 int a,b,n1,n2,t;
               ^
Main.c:5:7: warning: unused variable 'b' [-Wunused-variable]
 int a,b,n1,n2,t;
       ^
Main.c:5:5: warning: unused variable 'a' [-Wunused-variable]
 int a,b,n1,n2,t;
     ^
*/

Double click to view unformatted code.


Back to problem 59