6个回答

#include
int Func(int n);
int main( )
{
int n,result;
printf("Input n:");
scanf("%d",&n);
if(n1000000)
{
printf("Input error!\n");
}
else
{
result=Func(n);
printf("%d\n",result);
}
}
int Func(int n)
{
int m,i;
for(m=999;m>=100;m--)
{
if(n%m==0)
return m;
}

``````}
``````
qq_42331081 回复qq_42331081: 20行的i就不用定义了，只要定义一个m就行了

qq_42331081 回复qq_42331081: 第八行换成if（n<1000||n>1000000）

qq_42331081 有点小问题，给你点建议：1

int Func(int n) {
int array[n];
int i,j = 0;
if (n < 1000 || n > 1000000) {
printf("Input error!\n");
return -1;
}

``````for(i=1; i <= n/2; i++) {
if (n%i == 0) {
array[j] = i;
j++;
printf("find one: %d\n", i);
}
}
if (j >= 3) {
printf("\nlast three is: %d %d %d\n", array[j-3], array[j-2], array[j-1]);
}
return 0;
``````

}

for(i=n/2; i >= 1; i-- {
if (n%i == 0) {
array[j] = i;
j++;
printf("find one: %d\n", i);
if(3 == j)
break;
}
}
if (j >= 3) {
printf("\nlast three is: %d %d %d\n", array[0], array[1], array[2]);
}
return 0;

import java.util.Scanner;
public class Func {
public static void main(String[] args){

Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] list = new int[n];
int j = 0;
if(n < 1000 ||n>1000000){
System.out.println("Input error");
}
else{
for(int i = 2;i < n;i++){

if(n % i == 0){
list[j] = i;
j++;
}

``````      }
``````

}
System.out.println(n/list[0]);
System.out.println(n/list[1]);
System.out.println(n/list[2]);

}
}

static int Func(int n)
{
if (n >= 1000 && n <= 1000000)
{
for (int i = 999; i > 100; i--)
{
if (0 == n % i)
{
return i;
}
}
return -1;
}
else
{
return -1;
}
}

``````
``````

2 年多之前 回复