代碼錯誤在哪?。。。求教大神
/*
問題描述:
已知整數(shù)a、b、c。你的任務(wù)是求出區(qū)間[a,b]內(nèi)的整數(shù),滿足該數(shù)與“該數(shù)的所有因數(shù)(不包括本身但
包括1,1的因數(shù)和按0處理)相加之和”的差的絕對值小于等于c的數(shù)字。例如27的因數(shù)是1、3、9。那么27
與27的所有因數(shù)和的差為:27-(1+3+9)=14。
輸入與輸出要求:
輸入三個整數(shù)a、b、c。a、b代表所求區(qū)間范圍,滿足1<=a<=b<=10000,c代表限制條件,c>=0。輸出滿足
條件的整數(shù),每五個數(shù)為一行,整數(shù)之間用tab分隔,最后一個數(shù)后為換行符。當(dāng)該區(qū)間沒有符合條件的整
數(shù)時,輸出“There is no proper number in the interval.”
程序運(yùn)行效果:
Sample 1:
1 10000 0↙
6? ? ? ? ? 28? ? ? ? 496? ? ? ?8128↙
Sample 2:
2000 5000 4↙
2048? ? 2144? ? ?4030? ? ?4096↙
Sample 3:
900 1000 0↙
There is no proper number in the interval.↙
*/
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,n;//定義變量,a<=n<=b
scanf("%d %d %d",&a,&b,&c);
n=a;
int sum;//sum為因數(shù)之和
while(n<=b)
{
sum=0;//因數(shù)之和初始值為零?
int factor;//factor為因數(shù)
factor=1;//定義因數(shù)初始值?
while(factor<n)//窮舉求出n所有因數(shù)?
{
if(n%factor==0)//判斷factor是否為n的因數(shù)?
sum+=factor;//如果是,則求和?
factor++;//factor自加?
}
int difference,flag=0;//difference為sum與n的差值,flag控制一行最多五個數(shù)?
difference=sum-n;
if(fabs(difference)<=c)//判斷difference是否小于c?
{
printf("%d\t",n);//輸出符合條件的n?
flag++;
}
if(flag%5==0)//每五個數(shù)換行?
printf("\n");
while(n==b)
{
if(flag==0)//最終沒有數(shù),則輸出語句:?
{
printf("There is no proper number in the interval.");
? }
}
n++;
}
printf("\n");
return 0;?
}
2019-08-03