问题
I've been working on a project euler problem, which by their very nature coerce you to use data types with big storage.
#include <stdio.h>
#include <conio.h>
#define num 600851475143
int main()
{
long long i, j, count=0, number=num, k;
for(i=2;number!=1;i++)
{
count=0;
for(j=1;j<=i;j++)
{
if((i%j)==0)
{
count++;
}
}
for(k=0;k<100000000;k++)
{}
if(count==2)
{
printf(" %d\n", i);
if(number%i==0)
{
number/=i;
printf(" %d\n", number);
printf("%d\n", i);
i=2;
}
}
}
getch();
return 0;
}
When I compile and run the program, there is nothing printed for number. I have tried various printf conversions %ll, %l, I have changed data types. I am using GNU GCC compiler. What should I do?
回答1:
You should (re)read the documentation, I guess.
%ll didn't work since ll is not a complete specifier, it's just a modifier for the actual conversion specifier, which should follow.
Try %lld.
回答2:
The correct format for printf is %lld. Moreover you should use a prefix for your constant num, because this integer constant is too large to be hold in long type.
#define num 600851475143LL
Perhaps should you avoid lower-case macro's identifiers?
来源:https://stackoverflow.com/questions/13194067/trouble-with-printf-conversion-long-long