提问VC++的long long数据类型

C++语言 码拜 9年前 (2015-05-11) 1307次浏览 0个评论
 

int x=1; int y=9;//除数 
int sh=0; 
int yu=0;   
 div_t temp;  
 temp = div( x, y );  
sh=temp.quot; //商  
yu=temp.rem; ///余*/
cout<<sh<<endl;
cout<<yu<<endl;
//////////div为c++函数求商和余数如果用long long怎么实现,有没有用这个类型求商和余数的函数知道的告诉我好不好,谢谢

4分
1.换最新的VS
2.用C++
3.用std::div( lldiv_t std::div(long long, long long) )
3分
vc没有long long,vc的64位整型是用__int64。
3分
long long 就是__int64    
3分
int main(void)
{
	long x = 1; long y = 9;//除数 
	int sh = 0;
	int yu = 0;
	lldiv_t temp;
	temp = lldiv(x, y);
	sh = temp.quot; //商  
	yu = temp.rem; ///余*/
	cout << sh << endl;
	cout << yu << endl;
	return 0;
}
4分
          C++ Language Reference  
Data Type Ranges  
See Also   
 Collapse All Expand All    Language Filter: All Language Filter: Multiple Language Filter: Visual Basic Language Filter: C# Language Filter: C++ Language Filter: J# Language Filter: JScript  
 Visual Basic (Declaration) 
 Visual Basic (Usage) 
 C# 
 C++ 
 J# 
 JScript 

For 32-bit and 64-bit compilers, Microsoft Visual C++ recognizes the types shown in the table below. Note that the following type also have unsigned forms:

int (unsigned int)

__int8 (unsigned __int8)

__int16 (unsigned __in16)

__int32 (unsigned __in32)

__int64 (unsigned __in64)

char (unsigned char)

short (unsigned short)

long (unsigned long)

long long (unsigned long long)

Type Name  Bytes  Other Names  Range of Values  
int
 4
 signed
 –2,147,483,648 to 2,147,483,647
 
__int8
 1
 char, signed char
 –128 to 127
 
__int16
 2
 short, short int, signed short int
 –32,768 to 32,767
 
__int32
 4
 signed, signed int, int
 –2,147,483,648 to 2,147,483,647
 
__int64
 8
 long long, signed long long
 –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
 
bool
 1
 none
 false or true
 
char
 1
 none
 –128 to 127
 
short
 2
 short int, signed short int
 –32,768 to 32,767
 
long
 4
 long int, signed long int
 –2,147,483,648 to 2,147,483,647
 
long long
 8
 none (but equivalent to __int64)
 –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
 
enum
 4
 none
 Same as int
 
float
 4
 none
 3.4E +/- 38 (7 digits)
 
double
 8
 none
 1.7E +/- 308 (15 digits)
 
long double
 same as double
 none
 same as double
 
wchar_t
 2
 __wchar_t
 0 to 65,535
 

A variable of __wchar_t designates a wide-character or multibyte character type. By default wchar_t is a typedef for unsigned short. Use the L prefix before a character or string constant to designate the wide-character-type constant. When compiling with /Zc:wchar_t or /Za, the compiler can distinguish between an unsigned short and wchar_t for function overload purposes.

Signed and unsigned are modifiers that can be used with any integral type except bool. The char type is signed by default, but you can specify /J (compiler option) to make it unsigned by default.

The int and unsigned int types have the size of the system word: four bytes. However, portable code should not depend on the size of int.

Microsoft C/C++ also features support for sized integer types. See __int8, __int16, __int32, __int64 for more information. Also see Integer Limits.

See Fundamental Types for more information on the restrictions of the sizes of each type.

See Also
Reference
C++ Keywords
Fundamental Types

 To make a suggestion or report a bug about Help or another feature of this product, go to the feedback site. 

4分
          C++ Language Reference  
C++ Integer Constants  
See Also   
 Collapse All Expand All    Language Filter: All Language Filter: Multiple Language Filter: Visual Basic Language Filter: C# Language Filter: C++ Language Filter: J# Language Filter: JScript  
 Visual Basic (Declaration) 
 Visual Basic (Usage) 
 C# 
 C++ 
 J# 
 JScript 

Integer constants are constant data elements that have no fractional parts or exponents. They always begin with a digit. You can specify integer constants in decimal, octal, or hexadecimal form. They can specify signed or unsigned types and long or short types.

Grammar
integer-constant: 
decimal-constant integer-suffixopt 

octal-constant integer-suffixopt 

hexadecimal-constant integer-suffixopt 

“”c-char-sequence””

decimal-constant: 
nonzero-digit 

decimal-constant digit

octal-constant: 

octal-constant octal-digit

hexadecimal-constant: 
0x hexadecimal-digit 

0X hexadecimal-digit 

hexadecimal-constant hexadecimal-digit

nonzero-digit: one of 
1 2 3 4 5 6 7 8 9

octal-digit: one of 
0 1 2 3 4 5 6 7

hexadecimal-digit: one of 
0 1 2 3 4 5 6 7 8 9 

a b c d e f 

A B C D E F

integer-suffix: 
unsigned-suffix long-suffixopt 

long-suffix unsigned-suffixopt

unsigned-suffix: one of 
u U

long-suffix: one of 
l L

64-bit integer-suffix: 
i64 LL ll

To specify integer constants using octal or hexadecimal notation, use a prefix that denotes the base. To specify an integer constant of a given integral type, use a suffix that denotes the type.

To specify a decimal constant, begin the specification with a nonzero digit. For example:

  Copy Code 
int i = 157;   // Decimal constant
int j = 0198;  // Not a decimal number; erroneous octal constant
int k = 0365;  // Leading zero specifies octal constant, not decimal
 

To specify an octal constant, begin the specification with 0, followed by a sequence of digits in the range 0 through 7. The digits 8 and 9 are errors in specifying an octal constant. For example:

  Copy Code 
int i = 0377;   // Octal constant
int j = 0397;   // Error: 9 is not an octal digit
 

To specify a hexadecimal constant, begin the specification with 0x or 0X (the case of the “x” does not matter), followed by a sequence of digits in the range 0 through 9 and a (or A) through f (or F). Hexadecimal digits a (or A) through f (or F) represent values in the range 10 through 15. For example:

  Copy Code 
int i = 0x3fff;   // Hexadecimal constant
int j = 0X3FFF;   // Equal to i
 

To specify an unsigned type, use either the u or U suffix. To specify a long type, use either the l or L suffix. For example:

  Copy Code 
unsigned uVal = 328u;             // Unsigned value
long lVal = 0x7FFFFFL;            // Long value specified 
                                  //  as hex constant
unsigned long ulVal = 0776745ul;  // Unsigned long value
 

To specify a 64-bit integral type, use the LL, ll or i64 suffix. For example,

  Copy Code 
// 64bitsuffix.cpp
#include <stdio.h>
enum MyEnum {
   IntType,
   Int64Type
};

MyEnum f1(int) {
   printf(“in f1(int)\n”);
   return IntType;
}

MyEnum f1(__int64) {
   printf_s(“in f1(__int64)\n”);
   return Int64Type;
}

int main() {
   MyEnum t1 = f1(0x1234), t2 = f1(0x1234i64);
}
 

Output
  
in f1(int)
in f1(__int64)
 

See Also
Reference
Literals (C++)

 To make a suggestion or report a bug about Help or another feature of this product, go to the feedback site. 

用vs的long long来求商和余数怎么做
4分
long long a,b,c;
a=1000000001234ll;
b=1000ll;
c=a%b;
printf("%lld\n",c);//234
5分
long long a,b,c,d;
a=1000000001234ll;
b=1000ll;
c=a/b;
d=a%b;
printf("%lld,%lld\n",c,d);
5分
乍看起来c++的cin、cout在输入、输出上比c的scanf、printf简单,不用格式控制符!
但是不用格式控制符,输入输出恰好是你期望的格式的时候好说;等到输入输出不是你期望的格式的时候,你就会觉得还是用格式控制符更方便、更靠谱。
摒弃cin、cout!
使用scanf、printf。
5分
用lldiv处理long long

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明提问VC++的long long数据类型
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!