该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
对7帖做一更正:删除
if(iCount*iCount==2*liDate) break; /*无结果*/
这一句,不然程序会认为18,50,72之类的数无解.
改正后的程序如下:
#include
#include
main()
{
long liDate; /*输入的正整数*/
long iCount;/*项数*/
long i,min,max;
int flag=0;
system("cls");
printf("Please inout the number:\n",&liDate);/*输入正整数*/
scanf("%ld",&liDate);
for(iCount=(long)sqrt(2*liDate);iCount>=2;iCount--)
if(2*liDate%iCount==0)
if(iCount%2) /*项数为奇数*/
{
flag=1;
min=liDate/iCount-(iCount-1)/2;
max=liDate/iCount+(iCount-1)/2;
for(i=min;i<=max;i++)
printf("%ld ",i);
printf("\n\n");
}
else if(2*liDate/iCount%2) /*项数为偶数*/
{
flag=1;
min=liDate/iCount-iCount/2+1;
max=liDate/iCount+iCount/2;
for(i=min;i<=max;i++)
printf("%ld ",i);
printf("\n\n");
}
printf("\n");
if(flag==0) printf("NONE\n");
system("pause");
}