Page 1 of 1

data type... (long int, long long int)

Posted: Sun Jul 16, 2006 5:57 am
by bidol
hi,

i don't know how 'long long int' work.

for example,

i hava input...
1 2
3 4
5 6
7 8
and first code,

Code: Select all

#include <stdio.h> 
 int main() 
{ 
   long long int a, b; 
  
   while (scanf ("%lld%lld",&a, &b)!=EOF){ 
	   printf("%lld   %lld\n", a, b);
   } 
return 0;
gives output
1 0
3 0
5 0
7 0
and second code,

Code: Select all

#include <stdio.h> 
int main() 
{ 
   long int a, b; 
  
   while (scanf ("%ld%ld",&a, &b)!=EOF){ 
	   printf("%ld   %ld\n", a, b);
   } 
return 0;
}
now, it gives output,
1 2
3 4
5 6
7 8

the first code use 'long long int' and secode cod use 'long int'
other things equal, in both code.

but the output is different.

of course, second one is right.
and first output is quite strange for me... i can't understand...

can anybody help me?...

Posted: Sun Jul 16, 2006 9:09 am
by ayon
your compiler doesn't support long long data type correctly, but the judge's compiler does

Posted: Sun Jul 16, 2006 9:13 am
by jan_holmes
I don't know why, but I think it is more safe if you use cin and cout rather than scanf() and printf()...

Code: Select all

#include <stdio.h> 
#include <iostream>

using namespace std; 

int main() 
{ 
   long long a = 0; 
   long long b = 0;
  
   while (cin >> a >> b){ 
      cout << a << b << "\n"; 
   } 
   return 0;
} 

Posted: Sun Jul 16, 2006 11:24 am
by jtmh
If you compile on Windows, using "%I64d" instead of "%lld" may work.

Posted: Sun Jul 16, 2006 7:51 pm
by emotional blind
jan_holmes,
which compiler do u use?
i found this particular situation on QUINCY

BTW, holmes is my most fevourite character.
what is ur full name?

Posted: Mon Jul 17, 2006 12:41 pm
by jan_holmes
I'm using dev cpp... My real name is not related to holmes actually... :P I also like sherlock holmes... :D nice to meet you... btw, what kind of situation are you talking about ??? :oops:

Posted: Mon Jul 17, 2006 6:47 pm
by emotional blind
I was talking about the situation:
the problem with printf("%lld",value);

Posted: Wed Nov 29, 2006 11:09 pm
by barlow
I am also coding with Dev CPP, 4.9.9.2 and I'm interested how to print unsigned long long numbers with printf ?

Posted: Wed Nov 29, 2006 11:34 pm
by Jan
For Vcc (windows) use "%I64u", and for Gcc (Linux) use "%llu". I havent used Dev CPP. So, I dont know the identifier of 'unsigned long long' for Dev CPP. Try using any of the given. Hope it works.