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

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
bidol
New poster
Posts: 7
Joined: Sun Jul 10, 2005 1:14 pm

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

Post by bidol » Sun Jul 16, 2006 5:57 am

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?...
sorry, i'm not good at english.

ayon
Experienced poster
Posts: 161
Joined: Tue Oct 25, 2005 8:38 pm
Location: buet, dhaka, bangladesh

Post by ayon » Sun Jul 16, 2006 9:09 am

your compiler doesn't support long long data type correctly, but the judge's compiler does
ishtiak zaman
----------------
the world is nothing but a good program, and we are all some instances of the program

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

Post by jan_holmes » Sun Jul 16, 2006 9:13 am

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;
} 

jtmh
New poster
Posts: 16
Joined: Sat Jul 15, 2006 8:34 pm
Location: Taiwan

Post by jtmh » Sun Jul 16, 2006 11:24 am

If you compile on Windows, using "%I64d" instead of "%lld" may work.
Last edited by jtmh on Sun Jul 16, 2006 8:28 pm, edited 1 time in total.

User avatar
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind » Sun Jul 16, 2006 7:51 pm

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?

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

Post by jan_holmes » Mon Jul 17, 2006 12:41 pm

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:

User avatar
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind » Mon Jul 17, 2006 6:47 pm

I was talking about the situation:
the problem with printf("%lld",value);

barlow
New poster
Posts: 2
Joined: Mon Nov 20, 2006 5:47 pm

Post by barlow » Wed Nov 29, 2006 11:09 pm

I am also coding with Dev CPP, 4.9.9.2 and I'm interested how to print unsigned long long numbers with printf ?

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Wed Nov 29, 2006 11:34 pm

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.
Ami ekhono shopno dekhi...
HomePage

Post Reply

Return to “C”