Basic Data Types

Some C++ data types, their format specifiers, and their most common bit widths are as follows:ios

  • Int ("%d"): 32 Bit integer
  • Long ("%ld"): 64 bit integer
  • Char ("%c"): Character type
  • Float ("%f"): 32 bit real value
  • Double ("%lf"): 64 bit real value

Reading
To read a data type, use the following syntax:ide

scanf("`format_specifier`", &val)

For example, to read a character followed by a double:spa

char ch;
double d;
scanf("%c %lf", &ch, &d);

For the moment, we can ignore the spacing between format specifiers.code


Printing
To print a data type, use the following syntax:orm

printf("`format_specifier`", val)

For example, to print a character followed by a double:blog

char ch = 'd';
double d = 234.432;
printf("%c %lf", ch, d);

Note: You can also use cin and cout instead of scanf and printf; however, if you are taking a million numbers as input and printing a million lines, it is faster to use scanf and printf.ip

Input Formatci

Input consists of the following space-separated values: intlongcharfloat, and double, respectively.element

Output Formatinput

Print each element on a new line in the same order it was received as input. Note that the floating point value should be correct up to 3 decimal places and the double to 9 decimal places.

Sample Input

3 12345678912345 a 334.23 14049.30493

Sample Output

3
12345678912345
a
334.230
14049.304930000

watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	int a;
	long long b;//變量數據類型的選擇:應該使用long long int,又可簡寫爲long long
	char c;
	float d;
	double e;
	cin >> a >> b >> c >> d >> e;
	cout << a << endl;
	cout << b << endl;
	cout << c << endl;
	/*咱們在這裏主要用到其中兩個:fixed 和 showpoint。
首先說fixed,以定點方式顯示實數,即顯示整數部分*/
	cout <<setiosflags(ios::fixed)<< setprecision(3)<<d<< endl;
	cout<<setiosflags(ios::fixed)<<setprecision(9) <<e;
	return 0;
}

主要考察基本變量吧,注意long long ;

相關文章
相關標籤/搜索