义爨 : 务眍恹 镳钽疣祆桊钼囗 磬 ++.

1.骡邃屙桢

2.羊痼牝箴 镳钽疣祆

3. 蔫疱牝桠 镳屣痤鲥耨铕 觐祆屙蜞痂

4.羊囗溧痱睇 蜩稃 溧眄 C++

5.物屦圉梃 忖钿 恹忸溧 溧眄 C++

6.橡孱狃噻钼囗 蜩镱 溧眄 C++

7.鲤梏戾蜩麇耜桢 铒屦圉梃

8.项朦珙忄蝈朦耜桢 蜩稃 溧眄 C++: 耱痼牝箴

 

1.骡邃屙桢

赅驿铎 琨赍 镳钽疣祆桊钼囗 耋耱怏弪 铖眍忄, 徨 珥囗 觐蝾痤 礤忸珈铈眍 磬镨襦螯 溧驽 襦祛 镳铖蝾 镳钽疣祆.

溧眄铋 蝈戾 疣耨爨蝠桠帼蝰 铖眍恹 C++:

      耱痼牝箴 镳钽疣祆

      镥疱戾眄

      徉珙恹 铒屦圉梃 忖钿/恹忸溧

      觐祆屙蜞痂

      囵梏戾蜩麇耜桢 铒屦圉梃

      铒屦圉梃 桧牮屐屙蜞

      镳孱狃噻钼囗桢 蜩镱

      徼犭桀蝈黜 趔黻鲨.

 

2.羊痼牝箴 镳钽疣祆

朽耨祛蝠桁 襦禧 镳铖蝾, 镳桁屦 镳钽疣祆 磬 C++, 觐蝾疣 镳铖蝾 恹忸滂 蝈犟 耦钺龛 磬 疣.

#include <iostream>

using namespace std;

int main()

{

cout << " 篦篑 镳钽疣祆桊钼囹 C++\n";

return 0;

}

湾耢铗 磬 疋铋 礤犷朦 疣珈屦, 铗 镳桁屦 溴祛眈蝠桊箦 蜩镨黜簋 耱痼牝箴 镳钽疣祆 磬 C++. 朽耨祛蝠桁  耱痼牝箴 溴蜞. 泽黻鲨 镳邃耱噔 耦犷 铖眍怏, 磬 觐蝾痤 耱痤栩 膻徉 镳钽疣祆 C++. 泥眄 镳钽疣祆 耦耱铊 桤 邃桧耱忮眄铋 趔黻鲨 磬玮囗桢 main ().

耦耱噔 铋 趔黻鲨 礤 怩钿 溻 镥疴 耱痤麝 觐溧, 磬麒磬桢 耦 耠钼 #include using. 枢 桤忮耱眍, 趔黻鲨 祛驽 怩钿栩 耦耱噔 觌囫襦, 铎 耠篦噱 铐 磬琨忄弪 戾蝾漕 觌囫襦. 泽黻鲨 祛泱 耋耱忸忄螯 铗溴朦眍 铗 觌囫耦. 项赅 狍溴 疣耨爨蝠桠囹 腓 趔黻鲨, 觐蝾瘥 怆 礤玎忤耔禧扈, 赅 趔黻鲨 main() 镳桁屦.

褥 趔黻鲨. 署筱臌 耜钺觇, 桎簌桢 怦脲 玎 桁屙屐 main(), 怆 铗腓麒蝈朦眍 麇痱铋 趔黻鲨: 羼腓 猁 桴 礤 猁腩, 蝾 觐祜桦蝾 礤 耢钽 猁 铗腓麒螯 桁 镥疱戾眄铋 桦 漯筱钽 屐屙蜞 镳钽疣祆 铗 桁屙 趔黻鲨. 央钼 int, 镳邃忄邋 桁 趔黻鲨, 箨噻噱 磬 蝾, 黩  趔黻鲨 忸玮疣弪 珥圜屙桢 蜩镟 int.

义腩 趔黻鲨. 义腩 趔黻鲨 玎觌屙 翳泱痦 耜钺觇. 雾 铒疱溴 沭囗桷 犭铌 铒屦囹铕钼 镳钽疣祆. 澡泱痦 耜钺觇, 钺疣祀桢 蝈腩 趔黻鲨, 钺玎蝈朦睇. 镳桁屦 蝈腩 趔黻鲨 耦耱铊 怦邈 腓 桤 溻篚 铒屦囹铕钼: 钿桧 桤 龛 磬麒磬弪 耠钼铎 cout, 漯筱铋 - 耠钼铎 return.

泽黻鲨 main(). 暑沅 镳钽疣祆 磬 琨赍 C++ 玎矬耜噱蝰 磬 恹镱腠屙桢, 镥疴 桉镱腠屐 铒屦囹铕铎 耱囗钼栩 镥疴 铒屦囹铕 趔黻鲨 main(). 橡钽疣祆 祛驽 耦耱螯 桤 祉铈羼蜮 趔黻鲨, 觌囫耦 镳铟桴 屐屙蝾, 眍 镳 邋 玎矬耜 箫疣怆屙桢 怦邈溧 镥疱溧弪 趔黻鲨 main(). 篷腓 镳钽疣祆 礤 耦溴疰栩 趔黻鲨 桁屙屐 main(), 蝾 镳 镱稃蜿 玎矬耱栩 蜞牦 镳钽疣祆 狍溴 恹忮溴眍 耦钺龛 钺 铠栳赍. 镳钽疣祆圊 磬 C++ 疱嚯 溴轳蜮, 恹镱腠屐 桁 镳钽疣祆囔, 疋钿蝰 恹珙怏 趔黻鲨彘 main() 戾蝾漕 疣珉梓睇 钺牝钼. 署铎 蝾泐, 趔黻鲨 main() 祛驽 恹琨忄螯 漯筱桢, 礤玎忤耔禧 趔黻鲨.

物屦囹铕. 物屦囹铕 怆弪 耱痼牝箴眍 邃桧桷彘 镳钽疣祆 磬 C++. 镳桁屦 耦溴疰囹 2 铒屦囹铕:

1.   cout << " 篦篑 镳钽疣祆桊钼囹 C++\n";

2.   return 0;

襄疴 铒屦囹铕 玎溧弪 溴轳蜮桢 镱 恹忸潴 麴噻, 玎觌屙眍 赅恹麝, 磬 疣. 令朦眈蜮 铒屦囹铕钼 怆 箨噻囗扈 觐祜蝈痼 耦忮瘌栩 赅觐-腓犷 溴轳蜮桢. 侮铐鬣龛 铒屦囹铕 钺铉磬鬣弪 珥嚓铎 铟赅 玎蝾榛 - 怆弪 钺玎蝈朦睇. 物屦囹铕 return 0; 怆弪 箨噻囗桢 趔黻鲨 main() 忸玮疣蜩螯 珥圜屙桢 0 恹琨忄屐 铌痼驽龛; 溧眄铎 耠篦噱  祛驽 猁螯 觐祜桦蝾 桦 铒屦圉桀眄 耔耱屐. 疣玟咫桁 珥嚓囔 铗眍蝰 镳钺咫, 耔焘铍 忸玮疣蜞 赅疱蜿 镥疱躅溧 磬 漯筱簋 耱痤牦 漯.蜩 耔焘铍 礤 钺疣徉螓忄 觐祜桦蝾痤. 填骓 玎镨襦螯 礤耜铍 铒屦囹铕钼 磬 钿眍 耱痤赍, 疣玟咫栩 桴 膻猁 觐腓麇耱忸 镳钺咫钼, 蜞狍鲨 桦 矬耱 耱痤, 觐祜桦蝾 忸 怦艴 耠篦 钺疣犷蜞弪 桴 钿桧嚓钼. 篷螯 礤耜铍 桉觌屙栝 桤 钺泐 镳噔桦, 觐沅 觐祜桦蝾 钺疣徉螓忄弪 疣玟咫桢 耔焘铍. 襄疴铄 桉觌屙桢 - 耱痤赅 #include 镳钽疣祆眍泐 觐溧, 怆 滂疱牝桠铋 镳屣痤鲥耨铕 玎镨覃忄 钿眢 耱痤牦. 羊痤觐恹 觐眈蜞眚, 蜞觇, 赅 " 篦篑 镳钽疣祆桊钼囹 C++\n", 礤朦 疣玑桠囹 磬 礤耜铍 耱痤 觐溧.

 

3 蔫疱牝桠 镳屣痤鲥耨铕 觐祆屙蜞痂

襄疴 溻 耱痤觇, 觐蝾瘥 磬麒磬弪 镳桁屦, 怆 滂疱牝桠囔. 蔫疱牝桠 礤朦 聍栩囹 鬣耱 琨赅 C++, 钿磬觐 桴 桉镱朦珙忄龛 怆弪 礤钺躅滂禧. 羊痤赅 #include <iostream> 磬琨忄弪 滂疱牝桠铋 镳屣痤鲥耨铕 - 箨噻囗桢 觐祜桦蝾痼 怅膻麒螯 觐祜桦桊箦禧 羿殡 耦溴疰桁铄 漯筱钽 羿殡. 橡屣痤鲥耨铕铎 磬琨忄弪 耧弼栲朦磬 鬣耱 觐祜桦蝾疣, 钺疣徉螓忄 镱漕犴 滂疱牝桠 镥疱 磬鬣腩 镳铞羼襦 觐祜桦鲨 觐溧.#include 怆弪 钿眍 桤 祉钽桴 滂疱牝桠 镳屣痤鲥耨铕, 赅驿 桤 觐蝾瘥 镳邃忄弪 耔焘铍铎 #. 脏殡, 怅膻鬣屐 镱祛 滂疱牝桠 #include, 钺眍 磬琨忄 玎泐腩忸黜 羿殡铎.

青泐腩忸黜 羿殡. 镳桁屦 滂疱牝桠 #include 怆弪 箨噻囗桢 怅膻麒螯 桉躅漤 蝈犟 耦溴疰桁铄 羿殡 iostream 镥疱 觐祜桦鲨彘 觐溧.iostream 怆弪 镳桁屦铎 玎泐腩忸黜钽 羿殡 - 耦溴疰栩 铒桉囗, 礤钺躅滂禧 潆 疣犷螓 镥疱戾眄铋 cout 铒屦圉桢 <<. 铃 桴 铒桉囗栝 觐祜桦蝾痼 礤 狍溴 桤忮耱眍, 黩 珥圜栩 桁 cout, 箫铗疱犭屙桢 铒屦圉梃 << 狍溴 忸耧痂蝾 赅 礤觐痧尻蝽铄. 洋耱怏弪 祉铈羼蜮 玎泐腩忸黜 羿殡钼. C++ 玎泐腩忸黜 羿殡 礤 桁妣 疣聒桊屙.

蔫疱牝桠 using. 枢驿簋 镳钽疣祆 磬 C++ 祛骓 疣玑栩 磬 礤耜铍 蜞 磬琨忄屐 镳铖蝠囗耱 桁屙. 橡铖蝠囗耱忸 桁屙 磬琨忄弪 钺豚耱 镳钽疣祆, 觐蝾痤 疣耧铉磬弪 铒疱溴脲眄 耦忸牦镯铖螯 桁屙. 蒡 桁屙 礤桤忮耱睇 玎 镳邃咫囔 溧眄钽 镳铖蝠囗耱忄 桁屙. 蔫疱牝桠 using namespace std; 铉磬鬣弪, 黩 怦 铒疱溴脲眄 镳钽疣祆 桁屙 狍潴 铗眍耔螯 镳铖蝠囗耱怏 桁屙 桁屙屐 std. 朽珉梓睇 屐屙螓 镳钽疣祆 铒桉囗 桉镱朦珙忄龛屐 镳铖蝠囗耱忄 桁屙 std, 磬镳桁屦 镥疱戾眄 cout. 篷腓 礤 桉镱朦珙忄螯 滂疱牝桠 using, 蝾 桁 屐屙蜞 镳钽疣祆 镳桎弪 赅驿 疣 漕徉怆螯 桁 std: std::cout << " 篦篑 镳钽疣祆桊钼囹 C++\n";

蔫疱牝桠 using. 枢驿簋 镳钽疣祆 磬 C++ 祛骓 疣玑栩 磬 礤耜铍 蜞 磬琨忄屐 镳铖蝠囗耱 桁屙.

橡铖蝠囗耱忸 桁屙 磬琨忄弪 钺豚耱 镳钽疣祆, 觐蝾痤 疣耧铉磬弪 铒疱溴脲眄 耦忸牦镯铖螯 桁屙.蒡 桁屙 礤桤忮耱睇 玎 镳邃咫囔 溧眄钽 镳铖蝠囗耱忄 桁屙. 蔫疱牝桠 using namespace std; 铉磬鬣弪, 黩 怦 铒疱溴脲眄 镳钽疣祆 桁屙 狍潴 铗眍耔螯 镳铖蝠囗耱怏 桁屙 桁屙屐 std.篷腓 礤 桉镱朦珙忄螯 滂疱牝桠 using, 蝾 桁 屐屙蜞 镳钽疣祆 镳桎弪 赅驿 疣 漕徉怆螯 桁 std:

std::cout << " 篦篑 镳钽疣祆桊钼囹 C++\n";

暑祆屙蜞痂 怆 忄骓铋 鬣耱 膻犷 镳钽疣祆. 雾 镱祛汔 疣珙狃囹 溴轳蜮 镳钽疣祆 赅 疣琊噌铗麒牦, 蜞 膻犷祗 漯筱铎, 麒蜞屐 觐. 暑祜桦蝾 桡眍痂痼弪 怦, 黩 镱戾麇眍 镳钽疣祆 赅 觐祆屙蜞痂, 镱铎 觐祆屙蜞痂 礤 怅膻鬣 耦溴疰桁铄 桉镱腠屐钽 羿殡 龛赅 礤 怆 磬 躅 桉镱腠屙 镳钽疣祆.

念镱腠桁 镳桁屦 觐祆屙蜞痂扈.

#include <iostream>牋牋牋牋 //滂疱牝桠 镳屣痤鲥耨铕

using namespace std; //滂疱牝桠 using

int main() 牋牋牋牋牋牋牋 //趔黻鲨 桁屙屐 main

{牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋 //磬鬣腩 蝈豚 趔黻鲨

cout << " 赅驿铋 铛 疋铋 琨闬n; //铒屦囹铕

return 0;牋牋牋牋牋牋牋牋牋 //铒屦囹铕

}牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋 //觐礤 蝈豚 趔黻鲨

暑祆屙蜞痂 磬麒磬 溻铋眍 觐耦 麇痱 // 玎赅眵桠帼蝰 觐眦铎 耱痤觇. 暑祆屙蜞痂 祛驽 磬麒磬螯 赅 磬鬣脲 耱痤觇, 蜞 镱耠 赅觐泐-腓犷 铒屦囹铕.

暑祆屙蜞痂 疱觐戾礓箦蝰 桉镱朦珙忄螯, 黩钺 麇腩忮, 麒蜞栝 腓耱桧 镳钽疣祆, 镱龛爨 戾踵龛珈 疣犷螓 镳钽疣祆. 青溧鬣 觐祆屙蜞痂邂 - 溧螯 钺 镱耥屙 趔黻鲨铐桊钼囗 铗溴朦睇 犭铌钼 镳钽疣祆.

 

4 羊囗溧痱睇 蜩稃 溧眄 C++

襄疱戾眄 怆 趔礓囔屙蜞朦眍 鬣耱 膻犷泐 琨赅. 枢驿 镥疱戾眄 桁邋 桁 祛驽 镳桧桁囹 疣珉梓睇 珥圜屙. 襄疱戾眄 躔囗蝰 铒疱溴脲眄 篦囫蜿圊 镟蜩. 暑沅 镥疱戾眄铋 镳桉忄桠噱蝰 珥圜屙桢, 铐 玎镨覃忄弪 麇殛 镟蜩, 疋玎眄簋 溧眄铋 镥疱戾眄铋. 令朦眈蜮 琨觐 镳钽疣祆桊钼囗 镱滗屦骅忄 铒疱溴脲眄 磬犷 蜩镱 镥疱戾眄, 觐蝾瘥 怩钿 鲥臌, 忮耱忮眄 耔焘铍 蜩稃.

腕骓 麇蜿 珥囹 疣珥桷 戾驿 蝈痨桧囔 铒疱溴脲龛 镥疱戾眄铋 钺怆屙桢 镥疱戾眄铋. 吾怆屙桢 镥疱戾眄铋 镳邃镱豚汔弪 箨噻囗桢 桁屙 镥疱戾眄铋 (磬镳桁屦, var1) 邋 蜩镟 (int . .). 篷腓 镳 钺怆屙梃 镥疱戾眄铋 钿眍怵屐屙眍 恹溴弪 镟螯 镱 礤, 蝾 镳铊聃钿栩 铒疱溴脲龛 镥疱戾眄铋. 物屦囹铕 int var1; int var2; 怆 钺怆屙扈, 铒疱溴脲龛扈, 镱耜铍 恹溴弪 镟螯 镱 镥疱戾眄 var1 var2. 镳钽疣祆圊 鬣 箫铗疱犭 铒疱溴脲龛.

褥 镥疱戾眄铋. 镳桠邃屙眍 镳桁屦 桉镱朦珞 镥疱戾眄 桁屙囔 var1 var2. 褥屙, 溧忄屐 镥疱戾眄 漯筱桁 屐屙蜞 镳钽疣祆, 磬琨忄 桎屙蜩翳赅蝾疣扈.

橡 耦耱噔脲龛 桎屙蜩翳赅蝾疣 桉镱朦珞 狍赈 龛骓邈 忮瘐礤泐 疱汨耱痤, 鲨麴 铗 0 漕 9, 耔焘铍 镱澉屦觇忄龛 _.

襄疴 耔焘铍 桎屙蜩翳赅蝾疣 漕腈屙 猁螯 腓犷 狍赈铋, 腓犷 耔焘铍铎 镱澉屦觇忄龛. 碾桧 桎屙蜩翳赅蝾疣 蝈铕弪梓羼觇 礤 钽疣龛麒忄弪, 眍 犷朦眈蜮 觐祜桦蝾痤 礤 疣耧铉磬 桎屙蜩翳赅蝾瘥 潆桧铋 犷脲 64 耔焘铍钼. 暑祜桦蝾 疣珉梓噱 狍赈 忮瘐礤泐 龛骓邈 疱汨耱疣, 镱铎 桁屙 Var VAR 狍潴 忸耧痂龛爨螯 赅 疣珉梓睇. 赅麇耱忮 桁屙 镥疱戾眄 C++ 礤朦 桉镱朦珙忄螯 觌邂 耠钼. 孰邂铄 耠钼 -  玎疱珏疴桊钼囗眍 耠钼, 桁妣 铖钺铄 珥圜屙桢. 橡桁屦囔 觌邂 耠钼 祛泱 耠箧栩 int, class, if, while. 棋豚蝈朦眍, 黩钺 桁 镥疱戾眄铋 铗疣驵腩 耢 邋 耦溴疰桁钽.

皱腩麒耠屙磬 镥疱戾眄. 皱臌 蜩稃 耦铗忮蝰蜮簋 鲥臌 麒耠囔, 蜩 溧眄 眢驽 潆 蝾泐, 黩钺 铒屦桊钼囹 滂耜疱蝽 麒耠铎 钺牝钼.

洋耱怏弪 礤耜铍 鲥臌 蜩镱 溧眄, 桁妣 疣珉梓眢 潆桧.

朽耧痤耱疣礤眄 怆弪 蜩 int, 疣珈屦 镥疱戾眄铋 钽 蜩镟 怆弪 耔耱屐眍-玎忤耔禧.

32-疣琊漤 窝 疣珈屦 镥疱戾眄铋 int 疣忮 4 徉轵囔 (32 徼蜞), 黩 镱玮铍弪 躔囗栩 镥疱戾眄铋 蜩镟 int 珥圜屙 铗 -2 147 483 648 漕 2 147 483 647.

责嚆戾眚 镳钽疣祆, 桉镱朦珞彘 镥疱戾眄 蜩镟 int:

int var1;牋牋牋牋牋牋牋牋牋 //铒桉囗桢 镥疱戾眄铋 var1

int var2;牋牋牋牋牋牋牋牋牋 //铒桉囗桢 镥疱戾眄铋 var2

var1 =20;牋牋牋牋牋牋牋牋 //镳桉忸屙桢 珥圜屙 镥疱戾眄铋 var1

var2 = var1 +10;牋牋 //镳桉忸屙桢 珥圜屙 镥疱戾眄铋 var2

cout << "var1+10 疣忭 ";牋牋牋牋牋牋牋牋 //恹忸 耱痤觇

cout << var2 << endl;牋牋牋 //恹忸 珥圜屙 镥疱戾眄铋 var2

物屦囹铕 int var1; int var2; 铒疱溴 溻 鲥臌 镥疱戾眄 var1 var2. 孰邂铄 耠钼 int 铒疱溴弪 蜩 镥疱戾眄铋. 项漕犴 铒屦囹铕, 磬琨忄屐 钺怆屙扈, 漕腈睇 疣玟咫螯 蝾麝铋 玎蝾 (;), 赅 膻猁 漯筱桢 铒屦囹铕 镳钽疣祆. 襄疱 蝈 赅 忸耧铍钼囹 镥疱戾眄铋, 钺玎蝈朦眍 眢骓 钺忤螯 邋. 吾怆屙 镥疱戾眄 祛泱 疣耧铍嚆囹 膻犷 戾耱 镳钽疣祆. 湾 钺玎蝈朦眍 溴豚螯 怦 钺怆屙 镥疱戾眄 漕 镱怆屙 镥疴钽 桉镱腠屐钽 铒屦囹铕. 义 礤 戾礤, 钺怆屙 磬栳铍邋 鬣耱 箫铗疱犭屐 镥疱戾眄 鲥脲耦钺疣珥 镳铊玮钿栩 磬鬣脲 镳钽疣祆, 黩钺 钺羼镥麒螯 邋 箐钺铟栩噱祛耱. 物屦圉 镳桉忄桠囗. 物屦囹铕

var1 = 20;

var2 = var1 + 10;

- 镳桉忄桠帼 珥圜屙 镥疱戾眄 var1 var2.

- 珥嚓 = 铉磬鬣弪 镳桉忄桠囗桢 珥圜屙, 耱泐 镳噔铋 邈 鬣耱, 镥疱戾眄铋, 耱 脲忸 鬣耱.

- 镥疱戾眄铋 var1, 漕 钽 礤 桁邂 珥圜屙, 镳桉忄桠噱蝰 珥圜屙桢 20.

- 觐眈蜞眚 耦躔囗 疋铄 珥圜屙桢 磬 镳铗驽龛 怦邈 恹镱腠屙 镳钽疣祆.

- 珥圜屙桢 鲥腩 觐眈蜞眚 漕腈眍 耦溴疰囹 桧蝈疴嚯, 耦铗忮蝰蜮簋 滂囡噻铐 镳邃耱噔脲龛 鲥臌 麒皴.

- 铒屦囹铕 cout << "var1+10 疣忭 "; 恹忸滂 磬 疣 耱痤觐怏 觐眈蜞眚, 铒屦囹铕 cout << var2 << endl; 铗钺疣驵弪 珥圜屙桢 镥疱戾眄铋 var2.

- 铒屦圉 << 钺牝 cout 珥帼, 赅觇 钺疣珙 铗腓鬣螯 鲥腩 麒耠 铗 耱痤觇 赅 钺疣徉螓忄螯 赅驿铄 桤 龛.

- 羼腓 恹忸滂蝰 磬 疣 鲥腩 麒耠, 蝾 铐 铗钺疣驵弪 麒耠钼铎 纛痨囹, 镳 恹忸溴 耱痤觇 铐 铗钺疣驵弪 忤溴 蝈犟蜞.

-  赅驽蝰 铟邂桎睇, 眍 玎 桁 溴轳蜮扈 耱铊 戾踵龛珈 镥疱沭箸觇 铒屦圉栝, 蜩镨黜 潆 C++.

橡桁屦 镳钽疣祆

#include <iostream.h>

int main()

int year_now, age_now, another_year, another_age;

cout << "骡邃栩 蝈牦 泐 磬骒栩 ENTER.\n";

cin >> year_now;

cout << "骡邃栩 疋铋 忸琊囫 ( 泐溧).\n";

cin >> age_now;

cout << "骡邃栩 泐, 潆 觐蝾痤泐 恹 躅蜩蝈 箸磬螯 疋铋 忸琊囫.\n";

cin >> another_year;

another_age = another_year - (year_now - age_now);

if (another_age >= 0)

{

cout << " " << another_year << " 泐潴 忄 狍溴 ";

cout << another_age << "\n";牋牋

}

else牋牋牋 {

cout << " " << another_year << " 恹 妁 礤 痤滂腓顸!\n";}牋牋牋牋

return 0;

}

橡钽疣祆 玎镳帏桠噱 镱朦珙忄蝈 蝈牦 泐, 忸琊囫 镱朦珙忄蝈 妁 钿桧 泐, 玎蝈 恹麒耠弪 忸琊囫 镱朦珙忄蝈, 觐蝾瘥 狍溴 礤泐 忸 怛铕铎 忖邃屙眍 泐潴.

项耠 觐祜桦鲨 镳钽疣祆 邋 祛骓 玎矬耱栩 磬 恹镱腠屙桢. 绣珞朦蜞 恹镱腠屙 磬 疣礤 狍溴 恹汶溴螯 镳桁屦眍 蜞:

       骡邃栩 蝈牦 泐 磬骒栩 ENTER.

       2008

       骡邃栩 疋铋 忸琊囫 ( 泐溧).

       21

       骡邃栩 泐, 潆 觐蝾痤泐 恹 躅蜩蝈 箸磬螯 疋铋 忸琊囫.

       2017

       2017 泐潴 忄 狍溴 29

酿筱桢 鲥臌 蜩稃

洋耱怏弪 蜞赕 妁 礤耜铍 鲥臌 蜩镱: long short. 襄疱戾眄 蜩镱 long short 桁妣 翳犟桊钼囗睇 疣珈屦, 礤 玎忤 铗 桉镱朦珞屐铋 耔耱屐. 朽珈屦 蜩镟 long 怦邈溧 疣忮 4 徉轵囔 耦怙噤噱 疣珈屦铎 蜩镟 int 耠篦噱 32-疣琊漤 耔耱屐. 诣 long 祛驽 猁螯 铒桉囗 赅 long int: 戾驿 溻箪 蜞觇扈 铒桉囗扈 礤 疣珥桷. 诣 short 桁邋 疣珈屦, 疣忭 溻箪 徉轵囔. 蔫囡噻铐 珥圜屙栝 蜩镟 short - 铗 -32 768 漕 32 767. 吾疣犷蜿 镥疱戾眄 蜩镟 int 镳铊聃钿栩 猁耱疱 镱 耩噔礤龛 蜩镱 short. 篷腓 礤钺躅滂祛 铒桉囹 觐眈蜞眚 蜩镟 long, 蝾 镱耠 邋 珥圜屙 耠邃箦 箨噻囹 耔焘铍 L: long var = 7678L; // 铒桉囗桢 觐眈蜞眚 var 蜩镟 long

谚焘铍 镥疱戾眄 躔囗 鲥臌 麒耠, 耦溴疰帙桢 滂囡噻铐 铗 -128 漕 127. 朽珈屦 镟蜩, 玎龛爨屐 蜞觇扈 镥疱戾眄, 疣忮 1 徉轵.

软钽溧 耔焘铍 镥疱戾眄 桉镱朦珞 潆 镳邃耱噔脲龛 鲥臌 麒皴, 玎觌屙睇 箨噻囗眍 滂囡噻铐, 眍 泐疣玟 鬣 蜞觇 镥疱戾眄 躔囗蝰 ASCII-觐潲 耔焘铍钼.

亦犭桷 ASCII-觐漕 镳邃磬珥圜屙 潆 桧蝈痫疱蜞鲨 耔焘铍钼 赅 麒皴. 蒡 麒耠 玎觌屙 滂囡噻铐 铗 0 漕 127.

物屦圉桀眄 耔耱屐 Windows 疣聒桊 忮瘐睨 沭囗桷 钽 滂囡噻铐 漕 255 潆 蝾泐, 黩钺 怅膻麒螯 ASCII-蜞犭桷 耔焘铍 磬鲨铐嚯 嚯羿忤蝾 锺邂漕沭圄梓羼觇 耔焘铍.

襄疱戾眄 蜩镟 "char" 耋耱忮眄 铗腓鬣 铗 "int" 镳 恹镱腠屙梃 忖钿 溧眄 觌噔栲蝮瘥 恹忸溧 磬 疣.

谚焘铍 蜩

橡钽疣祆 潆 镥鬣蜩 麴嚆戾眚 蜞犭桷 ASCII (铗 32-泐 耔焘铍 (镳钺咫) 漕 126-泐 (耔焘铍 '~')):

#include <iostream.h>

int main()

{

int number;char character;

for (number = 32; number <= 126; number = number + 1 )

{

character = number;

cout << "谚焘铍 '" << character;

cout << "' 桁邋 ";

cout << dec << number << " (.) ";

cout << hex << number << " (耱礓.).\n";

}

return 0;

}

橡桠邃屙睇 觐 镳钽疣祆 恹忸滂 磬 疣:

谚焘铍 ' ' 桁邋 觐 32 (.) 桦 20 (耱礓.).

谚焘铍 '!' 桁邋 觐 33 (.) 桦 21 (耱礓.).

谚焘铍 '}' 桁邋 觐 125 (.) 桦 7D (耱礓.).

谚焘铍 '~' 桁邋 觐 126 (.) 桦 7E (耱礓.).桁忸朦睇 觐眈蜞眚 玎镨覃忄 钿桧铟睇 赅恹麝圊: '', 'V' . ., 耱痤觐恹 觐眈蜞眚 - 溻铋睇. 暑沅 觐祜桦蝾 怦蝠鬻噱 耔焘铍簋 觐眈蜞眚, 铐 玎戾弪 邋 磬 耦铗忮蝰蜮簋 ASCII-觐. 袜镳桁屦, 觐眈蜞眚 '' 狍溴 玎戾礤磬 麒耠铎 97. 谚焘铍 镥疱戾眄 祛骓 镳桉忄桠囹 珥圜屙 耔焘铍 觐眈蜞眚.

橡桁屦 疣犷螓 耔焘铍 镥疱戾眄 觐眈蜞眚囔.

char charvar1 ='A'; // 耔焘铍 镥疱戾眄 耦 珥圜屙桢 ''

char charvar2 ='\t '; // 耔焘铍 镥疱戾眄 耦 珥圜屙桢 耔焘铍 蜞狍鲨 cout <<chvar1;牋牋牋牋牋牋 // 恹忸 镥疱戾眄铋 磬 疣

cout <<chvar2;牋牋牋牋牋牋牋牋 // 恹忸 镥疱戾眄铋 磬 疣

charvar1 ='B';牋牋牋牋

cout <<charvar1;牋牋牋牋牋牋牋 // 恹忸 镥疱戾眄铋 磬 疣

cout <<抃n ';牋牋牋牋牋牋 // 镥疱躅 磬 耠邃簋 耱痤牦

洛耱忮眄 镥疱戾眄 觐眈蜞眚

襄疱戾眄 忮耱忮眄钽 蜩镟 躔囗 麒耠 溴蜩黜铋 纛痨 镳邃耱噔脲龛, 磬镳桁屦 3.1415927, 0.0000625, -10.2. 蜞觇 麒皴 羼螯 赅 鲥豚 鬣耱, 耱 耠邂 铗 溴蜩黜铋 蝾麝, 蜞 漯钺磬 鬣耱, 耱 耧疣忄 铗 礤.

襄疱戾眄 忮耱忮眄钽 蜩镟 镳邃磬珥圜屙 潆 躔囗屙 忮耱忮眄 麒皴.

C++ 桁妣蝰 蝠 忮耱忮眄 蜩镟: float, double long double.

float. float 耧铖钺屙 躔囗栩 麒耠, 耦溴疰帙桢 桧蝈疴嚯 铗 -3.4*1038 漕 3.4* 1038, 蝾黜铖螯 漕 皴扈 珥嚓钼 镱耠 玎蝾. 朽珈屦 蜩镟 float 疣忮 4 徉轵囔.

橡桁屦 忮耱忮眄 麒耠囔.

橡邃豚汔弪 忖羼蜩 疣滂篑 铌痼骓铖蜩, 赅麇耱忮 疱珞朦蜞蜞 恹忸滂蝰 磬 疣 镫铢噤 牮筱, 钽疣龛麇眄钽 溧眄铋 铌痼骓铖螯.

float rad;牋牋牋牋牋牋牋牋牋牋牋牋牋 // 镥疱戾眄 忮耱忮眄钽 蜩镟

const float pi =3.14159F;牋牋牋牋牋 // 忮耱忮眄 觐眈蜞眚

cout << "骡邃栩 疣滂篑 铌痼骓铖蜩: "; // 玎镳铖

cin >> rad;牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋 // 镱塍麇龛 疣滂篑

float area = pi *rad *rad; 牋牋牋牋牋 // 恹麒耠屙桢 镫铢噤 牮筱

cout <<"想铢噤 牮筱 疣忭 " << area << endl; // 恹忸 疱珞朦蜞蜞 磬 疣

诣稃 double long double. 拟 犷脲 牮箫睇 忮耱忮眄 蜩镟 溧眄 - double long double - 囗嚯钽梓睇 蜩矬 float 铗腓鬣 铗 礤泐 腓 疣珈屦囔 玎龛爨屐铋 镟蜩, 滂囡噻铐囔 珥圜屙栝 蝾黜铖螯 镳邃耱噔脲龛. 诣 double 玎龛爨弪 8 徉轵钼 镟蜩 躔囗栩 珥圜屙 蝾黜铖螯 漕 15 珥嚓钼 镱耠 玎蝾. 锗疣牝屦桉蜩觇 蜩镟 long double 玎忤 铗 觐祜桦蝾疣, 眍 鬣 怦邈 铐 耦怙噤帼 踵疣牝屦桉蜩赅扈 蜩镟 double.

 

#include <iostream.h>

#include <math.h>

int main()

{

float number;

cout << "骡邃栩 忮耱忮眄铄 麒耠.\n";

cin >> number;

cout << "暑疱睃 ";

cout.setf(ios::fixed);cout.precision(2);

cout << number;

cout << " 镳桁屦眍 疣忮 " << sqrt( number ) << ".\n";

return 0;

}牋牋牋牋牋牋牋牋牋牋 橡钽疣祆 磬镥鬣蜞弪 磬 疣礤:

骡邃栩 忮耱忮眄铄 麒耠.

200

暑疱睃 桤 200.00 镳桁屦眍 疣忮 14.14.

篷腓 耱痤牦 cout.setf(ios::fixed); 玎戾龛螯 磬 "cout.setf(ios::scientific);", 蝾 忤 疱珞朦蜞蜞 桤戾龛蝰:

骡邃栩 忮耱忮眄铄 麒耠.

200

暑疱睃 桤 2.00e+02 镳桁屦眍 疣忮 1.41e+01.

橡 恹忸溴 磬 疣 麒耠屙睇 珥圜屙栝 蜩镟 "float", "double" 桦 "long double" 忸珈铈眍 箨噻囗桢 蝾黜铖蜩 镳邃耱噔脲龛 溧眄 磬 疣礤 玎溧龛 礤觐蝾瘥 漕镱腠栩咫 镟疣戾蝠钼 铗钺疣驽龛, 磬镳桁屦, 铗钺疣驽龛 珥圜屙栝 纛痨囹 翳犟桊钼囗眍 桦 镫噔帼 蝾麝铋.

镳桠邃屙眍 镳桁屦 镳钽疣祆 忮耱忮眄铄 麒耠 铗钺疣驵弪 纛痨囹 翳犟桊钼囗眍 蝾麝铋 溻箪 溴蜩黜 珥嚓囔 镱耠 玎蝾.

蠕屙蜩翳赅蝾 "sqrt" 怆弪 桁屙屐 徼犭桀蝈黜铋 趔黻鲨 桤怆鬻屙 赈噤疣蝽钽 觐痦.

物桉囗桢 徼犭桀蝈觇 爨蝈爨蜩麇耜桴 趔黻鲨 耦溴疰栩 玎泐腩忸黜铎 羿殡 "math.h.阻耠 3.14159F - 镳桁屦 忮耱忮眄铋 觐眈蜞眚.

袜腓麒 . 泐忸痂 蝾, 黩 蜩 铋 觐眈蜞眚 忮耱忮眄, 耋趑桕 F 箨噻噱 邋 蜩 - float. 灶痨 镳邃耱噔脲龛 珥圜屙 觐眈蜞眚 - 眍痨嚯桤钼囗磬 溴蜩黜. 洛耱忮眄 觐眈蜞眚 蜩镟 double 怆 珥圜屙扈 镱 箪铍鬣龛. 碾 觐眈蜞眚 蜩镟 long double 礤钺躅滂祛 箨噻囹 耋趑桕 L.

碾 玎溧龛 珥圜屙栝 忮耱忮眄 麒皴 蜞赕 桉镱朦珞弪 耧铐屙鲨嚯 纛痨 玎镨耔, 镳邃磬珥圜屙 潆 镳邃耱噔脲龛 铟屙 犷朦 桦 铟屙 爨脲睃觇 麒皴.

橡弭桕 const.

橡钽疣祆 蜞赕 溴祛眈蝠桊箦 桉镱朦珙忄龛 镳弭桕襦 const, 桉镱朦珞弪 铒屦囹铕 const float PI = 3.14159F;孰邂铄 耠钼 const 镳邃耱怏弪 铒桉囗棹 蜩镟 镥疱戾眄铋 铉磬鬣弪, 黩 忸 怵屐 恹镱腠屙 镳钽疣祆 玎镳妁屙 桤戾螯 珥圜屙桢 铋 镥疱戾眄铋. 塔徉 镱稃蜿 桤戾龛螯 珥圜屙桢 镥疱戾眄铋, 铒桉囗眍 蜞觇 镳弭桕耦, 镳桠邃弪 恹溧麇 觐祜桦蝾痤 耦钺龛 钺 铠栳赍. 橡弭桕 const 桧纛痨桊箦 蝾, 黩 珥圜屙桢 镥疱戾眄铋 礤 狍溴 桤戾螯 躅溴 恹镱腠屙 镳钽疣祆.

橡弭桕 const 祛驽 镳桁屙螯 漯筱桁 屐屙蜞 镳钽疣祆.

bool

1.诣 bool 祛驽 桁弪 怦邈 溻 珥圜屙 - true false.

2.朽珈屦 镥疱戾眄铋 蜩镟 bool 疣忮 1 徉轵.

3.襄疱戾眄 蜩镟 bool 鬣 怦邈 桉镱朦珞 潆 躔囗屙 疱珞朦蜞蝾 疣珉梓睇 耩噔礤龛.

4.项漕犴 镥疱戾眄 鬣耱 磬琨忄 狍脲恹扈.

铃珑磬觐恹 蜩 溧眄

铃珑磬觐恹 蜩稃 溧眄 镳桁屙 蝈 耠篦, 觐沅 礤 礤钺躅滂祛耱 躔囗栩 镥疱戾眄 铗痂鲟蝈朦睇 珥圜屙. 昨钺 皲咫囹 蜩 徨珑磬觐恹, 眢骓 漕徉忤螯 镥疱 邈 磬玮囗桢 觌邂铄 耠钼 unsigned. 袜镳桁屦, 铒疱溴脲龛 徨珑磬觐忸 镥疱戾眄铋 蜩镟 char 狍溴 恹汶溴螯 耠邃簋 钺疣珙:

unsigned char uchvar; 蔓躅 玎 疣礻 漕矬耱桁 潆 溧眄钽 蜩镟 珥圜屙栝, 赅 镳噔桦, 镳桠钿栩 蝠箐眍 钺磬痼骅忄屐 铠栳赅. 耠邃簋 麴嚆戾眚 镳钽疣祆 镥疱戾眄 svar 蜩镟 int unsvar 蜩镟 unsigned int 镳桉忄桠噱蝰 钿眍 蝾 驽 珥圜屙桢, 疣忭铄 1 500 000 000:

int svar = 1500000000;

unsigned int unsvar = 1500000000;

svar = (svar *2) / 3;

unsvar = (unsignvar *2) / 3;

cout<<"琼嚓钼 镥疱戾眄 疣忭 <<svar<<endl;

cout<< "铃珑磬觐忄 镥疱戾眄 疣忭 "<<unsvar << endl;

吾 镥疱戾眄 箪眍驵 磬 2, 玎蝈 溴 磬 3. 湾耢铗 磬 蝾, 黩 镳噔桦 疱珞朦蜞 漕腈屙 镱塍麒螯 戾睃 桉躅漤钽 珥圜屙, 镳铎彐篁铟眍 恹麒耠屙桢 镳桠钿栩 疱珞朦蜞蝮, 犷朦祗, 麇 桉躅漤铄 麒耠. 亦赅 耔蝮圉 耱囗溧痱磬, 眍 玎鬣耱簋 铐 镳桠钿栩 铠栳赅. 亦, 磬镳桁屦, 钺彖 镥疱戾眄 栩钽 狍溴 耦溴疰囹 钿眍 蝾 驽 珥圜屙桢, 耦耱噔邋 2/3 铗 桉躅漤钽 疣忭铄 1 000 000 000. 皖 疱珞朦蜞 箪眍驽龛 恹 玎 漕矬耱桁 忮瘐龛 镳邃咫 潆 镥疱戾眄铋 svar. 项铎 疱珞朦蜞 疣犷螓 狍溴 恹汶溴螯 耠邃簋 钺疣珙: 琼嚓钼 镥疱戾眄 疣忭 431655765, 徨珑磬觐忄 镥疱戾眄 疣忭 1000000000义镥瘘 镥疱戾眄铋 耦 珥嚓铎 耦溴疰栩 礤忮痦铄 珥圜屙桢, 蝾 怵屐 赅 镥疱戾眄 徨 珥嚓, 觐蝾疣 桁咫 漕耱囹铟睇 滂囡噻铐 潆 镳邃耱噔脲龛 疱珞朦蜞蜞 箪眍驽龛, 耦溴疰栩 觐痧尻蝽 疱珞朦蜞. 悟颃溧 耠邃箦 恹忸: 礤钺躅滂祛 耠邃栩 玎 蝈, 黩钺 怦 珥圜屙, 觐蝾瘥 恹麒耠 镳钽疣祆, 耦铗忮蝰蜮钼嚯 滂囡噻铐囔 珥圜屙栝 蝈 镥疱戾眄, 觐蝾瘥 铐 镳桉忄桠帼蝰.

 

5.物屦圉梃 忖钿 恹忸溧 溧眄 C++

骡钿 镱祛 cin. 耠邃簋 麴嚆戾眚 镳钽疣祆 忖钿栩 珥圜屙桢 蝈祜屦囹箴 镱 脏疱磴彘蝮, 玎蝈 镳钽疣祆 镥疱忸滂  珥圜屙桢 嚯 皱朦耔 铗钺疣驵弪 疱珞朦蜞 磬 疣礤.

int ftemp;牋牋牋 // 蝈祜屦囹箴 镱 脏疱磴彘蝮

cout << "骡邃栩 蝈祜屦囹箴 镱 脏疱磴彘蝮: ";

cin >> ftemp;

int ctemp = (ftemp-32)*5/9;

cout<<"义祜屦囹箴 镱 皱朦耔 疣忭嗷<<ctemp<<'\n';

物屦囹铕 cin >> ftemp; 玎镳帏桠噱 忖钿 麒耠 铗 镱朦珙忄蝈. 骡邃屙眍 珥圜屙桢 镳桉忄桠噱蝰 镥疱戾眄铋 ftemp. 孰邂铄 耠钼 cin 怆弪 钺牝铎, 铒疱溴脲眄 C++ 潆 疣犷螓 耦 耱囗溧痱睇 镱蝾觐 忖钿.

项蝾 -  礤觐蝾疣 噌耱疣牿, 铗疣驵 镥疱戾龛 溧眄 铗 桉蝾黜桕 镳桢祉桕. 蒡铗 镱蝾 耦溴疰栩 溧眄, 忖钿桁 觌噔栲蝮瘥. >> 怆弪 铒屦圉桢 桤怆鬻屙. 雾 桤怆尻噱 溧眄 桤 镱蝾觐忸泐 钺牝, 耱泐 脲忸 鬣耱, 镳桉忄桠噱  溧眄 镥疱戾眄铋, 耱 镳噔铋 鬣耱.

蔓忸 桉镱朦珙忄龛屐 cout. 物屦囹铕 cout << "义祜屦囹箴 镱 皱朦耔 疣忭 " << ctemp << '\n '; 恹忸滂 磬 疣 耱痤牦, 玎觌屙眢 赅恹麝 怦脲 玎 礤 珥圜屙桢 镥疱戾眄铋 ctemp (<<ctemp) 镱耠 钽 恹镱腠弪 镥疱忸 磬 耠邃簋 耱痤牦 (<< '\n ').

cout 钺牝 C++, 镳邃磬珥圜屙 潆 疣犷螓 耦 耱囗溧痱睇 镱蝾觐 恹忸溧.

物屦圉 << 磬琨忄弪 铒屦圉桢 怦蜞怅, 觐镨痼弪 耦溴疰桁铄 镥疱戾眄铋, 耱 镳噔铋 邋 鬣耱, 钺牝, 耦溴疰帙栝 脲忸 邋 鬣耱. 物屦圉 << 磬镳噔弪 珥圜屙, 箨噻囗睇 镱蝾赍, 钺牝 cout, 觐蝾瘥 恹忸滂 桴 磬 疣. 谚焘铍 '\n' 觐眦 耱痤觐忸 觐眈蜞眚 怆弪 镳桁屦铎 箫疣怆彘 桦 escape-镱耠邃钼囹咫铖蜩.

溧眄铎 耠篦噱 蜞赅 镱耠邃钼囹咫铖螯 铉磬鬣弪, 黩 耠邃簋 恹忸 蝈犟蜞 磬黜弪 眍忸 耱痤觇.

物疱溴脲龛 镥疱戾眄 镳 镥疴铎 桉镱朦珙忄龛.

橡桁屦 铒疱溴脲龛 镥疱戾眄铋 ctemp 镱赅琨忄弪, 黩 祛骓 铒疱溴螯 镥疱戾眄簋 膻犷 戾耱 镳钽疣祆. 物疱溴脲龛 镥疱戾眄 蜞, 沅 铐 桉镱朦珞, 溴豚弪 腓耱桧 镳钽疣祆 镳铢 潆 镱龛爨龛, 镱耜铍 礤 礤钺躅滂祛耱 镱耱眄 忸玮疣螯 磬鬣腩 镳钽疣祆 潆 蝾泐, 黩钺 磬轵 铒桉囗 眢骓 镥疱戾眄.

蔓疣驽龛. 塔徉 觐灬桧圉 镥疱戾眄, 觐眈蜞眚 铒屦圉栝, 镳桠钿 恹麒耠屙棹 礤觐蝾痤泐 珥圜屙, 磬琨忄弪 恹疣驽龛屐: alpha+12 桦 (alpha-37)*beta/2. 绣珞朦蜞蝾 恹镱腠屙 怦艴 铒屦圉栝, 怩钿 耦耱噔 恹疣驽龛, 怆弪 珥圜屙桢. 蔓疣驽龛 襦扈 祛泱 怩钿栩 耦耱噔 漯筱桴 恹疣驽龛. 镳桁屦 alpha-37 beta/2 怆 恹疣驽龛扈. 脏牝梓羼觇 赅驿簋 镥疱戾眄簋 觐眈蜞眚, 磬镳桁屦 alpha 37, 祛骓 聍栩囹 鬣耱睇 耠篦噱 恹疣驽龛.

6. 橡孱狃噻钼囗 蜩镱 溧眄 C++

哏 C++ 疋钺钿礤 钺疣弪 恹疣驽龛扈, 怅膻鬣桁 皴 疣珉梓睇 蜩稃 溧眄.

赅麇耱忮 镳桁屦 疣耨祛蝠桁 耠邃簋 麴嚆戾眚:

int count = 7;

float avgw = 155.5F;

double totalw = count *avgw;

cout <<" 疣忮 " << totalw << endl;

卿羼 镥疱戾眄 蜩镟 int 箪眍驵弪 磬 镥疱戾眄簋 蜩镟 float, 疱珞朦蜞 镳桉忄桠噱蝰 镥疱戾眄铋 蜩镟 double. 暑祜桦鲨 镳铊聃钿栩 徨 铠栳铌, 镱耜铍 觐祜桦蝾瘥 漕矬耜帼 忸珈铈眍耱 恹镱腠屙 囵梏戾蜩麇耜桴 铒屦圉栝 铒屦囗溧扈 疣珥 蜩镱. C++ 镳邃镱豚汔弪, 黩 耢屮桠囗桢 蜩镱 溧眄 镳铊珙 耦珥囹咫 怆弪 玎潴礻铋 镳钽疣祆桉蜞, 镱铎 礤 戾弪 屐 疱嚯桤钼囹 疋铊 桎彖. 项漕犴 镱漉钿 铗鬣耱 钺耥弪 镱矬痦铖螯 C++, , 耦铗忮蝰蜮屙眍, 溧弪 镳钽疣祆桉蝮 犷朦 疋钺钿.

湾忭 镳孱狃噻钼囗 蜩镱. 朽耨祛蝠桁 溴轳蜮 觐祜桦蝾疣, 觐沅 铐 怦蝠鬻噱 恹疣驽龛 耦 耢屮囗睇扈 蜩镟扈. 枢驿 蜩 溧眄 祛骓 篑腩忭 聍栩囹 桄寤 桦 寤 镱 铗眍龛 漯筱桁 蜩镟.

儒疣瘐 蜩镱 溧眄. 鲤梏戾蜩麇耜桢 铒屦圉梃, 镱漕犴 + *, 溴轳蜮簋 耠邃簋 钺疣珙: 羼腓 桴 铒屦囗潲 桁妣 疣珉梓睇 蜩稃, 蝾 铒屦囗 犷脲 桤觇旎 蜩镱 狍溴 镳孱狃噻钼囗 犷脲 铌铎蠡 蜩矬. 项漕犴 镳孱狃噻钼囗 蜩镱 溧眄 镳铊聃钿 礤忭. 武磬觐 溴 耠篦噱 觐祜桦蝾 礤 耱铍 镱蝽 镳钼钿栩 镳孱狃噻钼囗 蜩镱. 务钺屙眍  赅襦弪 镳 疣犷蝈 钺牝囔. 卿羼 羿牝梓羼觇 狍溴 铒屦桊钼囹 耦狁蜮屙睇扈 蜩镟扈 溧眄. 铎 耠篦噱 眢骓 耦玟噔囹 耩邃耱忄, 恹镱腠桢 礤钺躅滂禧 镳孱狃噻钼囗 蜩镱, 镱耜铍 觐祜桦蝾 礤 耢铈弪 镳孱狃噻钼囹 镱朦珙忄蝈朦耜桢 蜩稃 溧眄 蜞, 赅 铐 溴豚  耦 耱囗溧痱睇扈 蜩镟扈. 哜睇 镳孱狃噻钼囗 蜩镱 耦忮瘌帼蝰 襦扈 镳钽疣祆桉蝾, 礤钺躅滂禧 蝈 耠篦, 觐沅 觐祜桦蝾 礤 祛驽 徨珙犷黜 镳孱狃噻钼囹 蜩稃 噔蝾爨蜩麇耜. C++ 耋耱怏弪 礤耜铍 疣珉梓睇 铒屦圉栝 镳桠邃屙 蜩镱.

哜睇 镳桠邃屙 蜩镱 C++ 忮潴 皴 忮顸爨 蝠遽钼囹咫.

int var =1500000000;

var = (var*10)/10;// 耠桫觐 犷朦 疱珞朦蜞

cout<<"琼圜屙桢 var 疣忭"<<var<<endl; // 礤忮痦 疱珞朦蜞

var = 1500000000; // 镳桠邃屙桢 蜩矬 double

var = (static_cast<double>(var)*10)/10;

cout << "琼圜屙桢 var 疣忭 " << var << endl;牋牋 // 忮痦 疱珞朦蜞

橡 箪眍驽龛 镥疱戾眄铋 var 磬 10, 镱塍鬣屐 疱珞朦蜞 疣忮 15 000 000 000 邈 礤朦 躔囗栩 溧驽 镱祛 蜩镟 unsigned int.

物屦囹铕 static_cast<double>(var) 耦玟噱 怵屐屙眢 镥疱戾眄簋 蜩镟 double, 耦溴疰帙簋 珥圜屙桢, 疣忭铄 珥圜屙棹 var. 蒡 怵屐屙磬 镥疱戾眄 箪眍驵弪 磬 10, 镱耜铍 疱珞朦蜞 蜞赕 桁邋 蜩 double, 镥疱镱腠屙 礤 镳铊聃钿栩. 青蝈 怵屐屙磬 镥疱戾眄 溴腓蝰 磬 10, 疱珞朦蜞 镳桉忄桠噱蝰 钺眍 鲥腩 镥疱戾眄铋 var.

橡桠邃屙桢 蜩镱 耠邃箦 桉镱朦珙忄螯 蝾朦觐 耠篦噱 镱腠铋 筲屦屙眍耱 邈 礤钺躅滂祛耱 镱龛爨龛, 潆 麇泐 铐 溴豚弪.

骂珈铈眍耱 镳桠邃屙 溴豚弪 蜩稃 溧眄 礤玎眄 铗 镱蝈眦栲朦睇 铠栳铌, 镱耜铍 觐祜桦蝾 礤 祛驽 镳铌铐蝠铍桊钼囹 觐痧尻蝽铖螯 溴轳蜮栝 镳 桤戾礤龛 蜩镱 溧眄.

7.鲤梏戾蜩麇耜桢 铒屦圉梃

C++ 桉镱朦珞 麇螓疱 铖眍忭 囵梏戾蜩麇耜桢 铒屦圉梃: 耠铈屙, 恹麒蜞龛, 箪眍驽龛 溴脲龛, 钺铉磬鬣屐 耦铗忮蝰蜮屙眍 +,-,*, /. 蒡 铒屦圉梃 镳桁屙桁 赅 鲥臌 蜩镟 溧眄, 蜞 忮耱忮眄. 洋耱怏 蜞赕 漯筱桢 囵梏戾蜩麇耜桢 铒屦圉梃, 桉镱朦珙忄龛 觐蝾瘥 礤 耱铍 铟邂桎眍. 洋耱怏弪 妁 钿磬 囵梏戾蜩麇耜 铒屦圉, 觐蝾疣 镳桁屙弪 蝾朦觐 鲥臌 麒耠囔 蜩镟 char, short, int long.

蒡 铒屦圉 磬琨忄弪 铒屦圉桢 铖蜞蜿 铗 溴脲龛 钺铉磬鬣弪 珥嚓铎 镳铞屙蜞 %.

绣珞朦蜞蝾 铋 铒屦圉梃, 桧钽溧 蜞赕 磬琨忄屐铋 蜩屐 镱 祛潴膻, 怆弪 铖蜞蝾, 镱塍鬣屐 镳 溴脲龛 邋 脲忸泐 铒屦囗溧 镳噔.

袜镳桁屦, 疱珞朦蜞蝾 恹镱腠屙 铒屦囹铕: a=10%8; 怆弪 麒耠 2.

哏 C++ 疣耧铍嚆噱 耩邃耱忄扈 潆 蝾泐, 黩钺 耦牮囹栩 疣珈屦 觐溧 皲咫囹 邈 磬汶漤. 武龛 桤 蜞觇 耩邃耱 怆 囵梏戾蜩麇耜桢 铒屦圉梃 镳桉忄桠囗桢.

犷朦眈蜮 琨觐 镳钽疣祆桊钼囗 蜩镨黜 怆弪 铒屦囹铕, 镱漕犴

var1 = var1 + var2;

溧眄铎 耠篦噱 镳铊玮钿栩 耠铈屙桢 玎戾龛屐 箧 耋耱怏邈 珥圜屙 钿眍泐 桤 耠嚆噱禧. C++ 耋耱怏弪 耧铖钺 耦牮囹栩 镱漕犴 铒屦囹铕, 镳桁屙 囵梏戾蜩麇耜桢 铒屦圉梃 镳桉忄桠囗桢.

亦觇 铒屦圉梃 觐灬桧桊簋 囵梏戾蜩麇耜簋 铒屦圉棹 铒屦圉棹 镳桉忄桠囗, 蝈 襦禧 桉觌 礤钺躅滂祛耱 桉镱朦珙忄龛 桁屙 镥疱戾眄铋 溻噫潲.

橡邃簌栝 铒屦囹铕 祛骓 玎镨襦螯 耠邃簋 钺疣珙: var1 += var2;

镳桉忄桠囗桢 觐灬桧桊箦蝰 漯筱桢 囵梏戾蜩麇耜桢 铒屦圉梃: -=, *=, /=, %= . .

橡桁屦 桉镱朦珙忄龛 囵梏戾蜩麇耜桴 铒屦圉栝 镳桉忄桠囗桢:

int ans = 27;

ans += 10;牋牋牋牋牋牋牋牋牋牋牋牋 // 蝾 驽 襦祛, 黩 ans = ans +10;

cout << ans << ",";

ans -= 7;牋牋牋牋牋牋牋牋牋牋牋牋牋 // 蝾 驽 襦祛, 黩 ans = ans -7;

cout << ans << ",";

ans *=2 ;牋牋牋牋牋牋牋牋牋牋牋牋牋 // 蝾 驽 襦祛, 黩 ans = ans *2;

cout << ans << ",";

ans /= 3;牋牋牋牋牋牋牋牋牋牋牋牋牋 // 蝾 驽 襦祛, 黩 ans = ans /3;

cout << ans << ",";

ans %= 3;牋牋牋牋牋牋牋牋牋牋牋牋 // 蝾 驽 襦祛, 黩 ans = ans %3;

cout << ans << endl;

软牮屐屙.

C++ 桁邋蝰 钿磬 铒屦圉, 觐蝾疣 怆弪 犷脲 耧弼梏梓眍, 礤驽腓 镳邃簌桢. 橡 镳钽疣祆桊钼囗梃 鬣耱 镳桴钿栩 桁弪 溴腩 筲咫梓屙桢 赅觐-腓犷 忮腓麒睇 磬 邃桧桷.

蒡 祛骓 皲咫囹  腩峄, 桉镱朦珞 铒屦囹铕

count=count+1;

桦 镱祛 耠铈屙 镳桉忄桠囗桢:

count += 1;牋牋 //筲咫梓屙桢 count 磬 1

皖 羼螯 妁 钿桧, 犷脲 矜囹, 麇 镳邃簌桢, 耧铖钺:

++count;牋牋牋牋 // 筲咫梓屙桢 count 磬 1

物屦圉 ++ 桧牮屐屙蜩痼弪, 桦 筲咫梓桠噱 磬 1, 疋铋 铒屦囗.

8 . 项朦珙忄蝈朦耜桢 蜩稃 溧眄 C++: 耱痼牝箴.

念 钽 猁腓 疣耨祛蝠屙 蝾朦觐 镥疱戾眄 耱囗溧痱睇 蜩镱, 蜞觇, 赅 float, char int.

项漕犴 镥疱戾眄 耧铖钺睇 镳邃耱噔螯 赅牦-腓犷 钿眢 忮腓麒眢 - 恹耦蝮, 耋祆, 珥圜屙桢 聍弪麒赅 . . 武磬觐 桧钽溧 铗溴朦睇 镥疱戾眄 猁忄弪 箐钺眍 钺滂螯 犷脲 耠铈睇 觐眈蝠箨鲨.

疱嚯铋 骅珥 禧 耦忮瘌噱 镱漕犴 溴轳蜮, 觐沅 铕汔龛珞屐 疣犷蝽桕钼 翳痨 铗溴臌 桦 耦耱噔屐 镳邃腩驽龛 桤 铗溴朦睇 耠钼.

C++ 觐眈蝠箨鲨扈, 疱嚯桤簋扈 钺滂礤龛 疣珥铕钿睇 溧眄, 怆 爨耨桠, 耱痼牝箴, 觌囫覃. 羊痼牝箴 怆弪 钺滂礤龛屐 镳铖螓 镥疱戾眄. 蒡 镥疱戾眄 祛泱 桁弪 疣珉梓睇 蜩稃: int, float . . C++, 耱痼牝箴 怆 钿眍 桤 耦耱噔桴 汶噔睇 觐眦屣鲨 琨赅 - 钺牝钼 觌囫耦.

谚眚嚓耔 耱痼牝箴 羿牝梓羼觇 桎屙蜩麇 耔眚嚓耔耋 觌囫襦.

悟腓麒 耱痼牝箴 铗 觌囫襦 玎觌噱蝰 耠邃簋: 耱痼牝箴 桉镱朦珞 赅麇耱忮 钺滂礤龛 溧眄, 觌囫覃 - 赅麇耱忮 钺滂礤龛 溧眄 趔黻鲨.

如篦 耱痼牝箴 玎觌噤噱 铖眍恹 潆 镱龛爨龛 觌囫耦 钺牝钼.

橡铖蜞 耱痼牝箴.

袜黜屐 疣耨祛蝠屙桢 耦 耱痼牝箴, 耦溴疰帙彘 蝠 镱, 溻 镱 桁妣 鲥臌 蜩 钿眍 镱脲 - 忮耱忮眄 蜩.

蒡 耱痼牝箴 镳邃磬珥圜屙 潆 躔囗屙 桧纛痨圉梃 觐祜脲牝簋 溴蜞 桤溴腓, 恹矬耜噱禧 羿狃桕铋.

镳桠邃屙眍 麴嚆戾眚 镳钽疣祆 铒疱溴弪 耱痼牝箴 part 镥疱戾眄 part1 蜩镟 part.

青蝈 镱 镥疱戾眄铋 part 镳桉忄桠帼蝰 珥圜屙 恹忸蝰 磬 疣.

struct part牋牋牋牋牋牋牋牋牋牋牋牋 // 钺怆屙桢 耱痼牝箴

{

int modelnum;牋牋牋牋牋牋牋牋牋牋牋牋牋 // 眍戾 祛溴腓 桤溴腓

int partnum;牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋 // 眍戾 溴蜞腓

float cost;牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋 // 耱铊祛耱 溴蜞腓

};

int main()

{

part part1;牋牋 // 铒疱溴脲龛 耱痼牝箴眍 镥疱戾眄铋

part1.modelnum = 6244; // 桧桷栲腓玎鲨 镱脲

part1.partnum = 373;牋牋牋 // 镥疱戾眄铋 part1

part1.cost - 217.55F;

cout << "填溴朦 " << part1.modelnum;

cout << " 溴蜞朦 " << part1.partnum;

cout << " 耱铊祛耱 $" << part1.cost << endl;

return 0;

}

镳桁屦 镳桉篁耱怏 蝠 铖眍忭 囫镥牝 疣犷螓 耦 耱痼牝箴囔:

       铒疱溴脲龛 耱痼牝箴

       铒疱溴脲龛 镥疱戾眄铋 蜩镟 铋 耱痼牝箴

       漕耱箫 镱 耱痼牝箴.

项漯钺眍 疣耨祛蝠桁 赅驿 桤 桴 囫镥牝钼.

物疱溴脲龛 耱痼牝箴 玎溧弪 邋 忭篁疱眄 铕汔龛玎鲨, 铒桉 镱, 怩钿 耦耱噔 耱痼牝箴:

struct part

{

int modelnum;

int partnum;

float cost;

};

物疱溴脲龛 耱痼牝箴 磬麒磬弪 觌邂钽 耠钼 struct.

青蝈 耠邃箦 桁 耱痼牝箴.

吾怆屙 镱脲 耱痼牝箴 玎觌帼蝰 {}.

项耠 } 耠邃箦 蝾麝 玎蝾 (;) - 耔焘铍, 铉磬鬣栝 觐礤 铒疱溴脲龛 耱痼牝箴

物疱溴脲龛 耱痼牝箴 礤钺躅滂祛 潆 蝾泐, 黩钺 耦玟噔囹 磬 邈 铖眍忮 镥疱戾眄 钽 蜩镟. 燕祛 铒疱溴脲龛 耱痼牝箴 礤 耦玟噱 龛赅觇 镥疱戾眄, .. 礤 镳铊聃钿栩 龛 恹溴脲龛 翳玷麇耜铋 镟蜩, 龛 钺怆屙 镥疱戾眄铋. 蝾 驽 怵屐 铒疱溴脲龛 钺眍 镥疱戾眄铋 镳邃镱豚汔弪 恹溴脲龛 镟蜩 镱  镥疱戾眄簋. 亦觇 钺疣珙, 铒疱溴脲龛 耱痼牝箴 羿牝梓羼觇 玎溧弪 忭篁疱眄 铕汔龛玎鲨 耱痼牝箴睇 镥疱戾眄 镱耠 蝾泐, 赅 铐 狍潴 铒疱溴脲睇 .

襄疴 铒屦囹铕 趔黻鲨 main() 恹汶滂 耠邃簋 钺疣珙:  part part1;, 镳邃耱噔弪 耦犷 铒疱溴脲龛 镥疱戾眄铋 part1, 桁妣 蜩 part. 物疱溴脲龛 镥疱戾眄铋 铉磬鬣弪, 黩 镱  镥疱戾眄簋 恹溴弪 镟螯. 项 耱痼牝箴眢 镥疱戾眄簋 怦邈溧 铗忸滂蝰 耱铍 镟蜩, 耜铍 漕耱囹铟眍 潆 躔囗屙 怦艴 邋 镱脲. 镳桁屦 礤钺躅滂祛 恹溴腓螯 镱 4 徉轵 潆 溻篚 镱脲 蜩镟 int 4 徉轵 潆 镱 蜩镟 float. 礤觐蝾痤 耢脲  祛骓 聍栩囹 耱痼牝箴 part 眍恹 蜩镱 溧眄. 物疱溴脲龛 耱痼牝箴眍 镥疱戾眄铋 镱 疋铄祗 耔眚嚓耔耋 桎屙蜩黜 铒疱溴脲龛 镥疱戾眄铋 耱囗溧痱眍泐 蜩镟:

part part1; int varl;

亦觐 聃钿耱忸 礤 怆弪 耠篦嚅睇. 武磬 桤 鲥脲 琨赅 C++ - 皲咫囹 疣犷蝮 镱朦珙忄蝈朦耜桁 蜩镟扈 溧眄 爨犟桁嚯 镱躅驽 磬 疣犷蝮 耦 耱囗溧痱睇扈 蜩镟扈 溧眄. 暑沅 耱痼牝箴磬 镥疱戾眄 铒疱溴脲磬, 漕耱箫 邋 镱 忸珈铈屙 镳桁屙屙桢 铒屦圉梃 蝾麝

part1.modelnum = 6244;

项脲 耱痼牝箴 桎屙蜩翳鲨痼弪 镱祛 蝠艴 耦耱噔桴:

       桁屙 耱痼牝箴眍 镥疱戾眄铋 part1,

       铒屦圉梃 蝾麝 (.)

       桁屙 镱 modelnum.

物屦圉 蝾麝 磬琨忄弪 铒屦圉桢 漕耱箫 镱膻 耱痼牝箴.

马桁囗桢: 恹疣驽龛 桉镱朦珙忄龛屐 铒屦圉梃 蝾麝 (.) 磬 镥疴铎 戾耱 耱铊 礤 磬玮囗桢 耱痼牝箴 (part), 桁 耱痼牝箴眍 镥疱戾眄铋 (part1), 桁 镥疱戾眄铋 眢骓 潆 蝾泐, 黩钺 铗腓鬣螯 钿眢 镥疱戾眄簋 铗 漯筱铋. 镱扈 耱痼牝箴眍 镥疱戾眄铋 祛骓 钺疣螯 蜞 驽, 赅 钺睇扈 镳铖螓扈 镥疱戾眄. 疱珞朦蜞蝈 恹镱腠屙 铒屦囹铕 part1.modelnum = 6244; 镱膻 modelnum 镳桉忄桠噱蝰 珥圜屙桢 6244 镳 镱祛 钺眍 铒屦圉梃 镳桉忄桠囗.

橡桁屦 溴祛眈蝠桊箦 耧铖钺, 镳 镱祛 觐蝾痤泐 祛骓 桧桷栲腓玷痤忄螯 镱 镳邃忄痂蝈朦眍 铒疱溴脲眄铋 耱痼牝箴眍 镥疱戾眄铋. 镳钽疣祆 桉镱朦珞 溻 耱痼牝箴睇 镥疱戾眄.

int main()

{

part part1 = {6244,373,217.55F };// 桧桷栲腓玎鲨 镥疱

part part2;牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋牋 // 钺怆屙桢 镥疱戾眄铋

cout << "填溴朦 " << part1.modelnum;

cout << ", 溴蜞朦 " << part1.partnum;

cout << ", 耱铊祛耱 $" << part1.cost << endl;

part2 = part1; // 镳桉忄桠囗桢 耱痼牝箴睇 镥疱戾眄

cout << "填溴朦 " << part2.modelnum;

cout << ", 溴蜞朦 " << part2.partnum;

cout << ", 耱铊祛耱 $" << part2.cost <<endl;

return 0;

}

镳桁屦 铒疱溴脲睇 溻 镥疱戾眄 蜩镟 part: part1 part2.

项耠 蝾泐 赅 镱 镥疱戾眄铋 part1 桧桷栲腓玷痤忄睇, 镳铊聃钿栩 恹忸 桴 珥圜屙栝 磬 疣, 玎蝈 珥圜屙桢 镥疱戾眄铋 part1 镳桉忄桠噱蝰 镥疱戾眄铋 part2, 珥圜屙 邋 镱脲 蜞赕 恹忸蝰 磬 疣.

软桷栲腓玎鲨 镱脲 镥疱戾眄铋 part1 镳铊玮钿栩 祛戾眚 邋 铒疱溴脲龛: part part1 = { 6244, 373, 217.55 };琼圜屙, 觐蝾瘥 镳桉忄桠帼蝰 镱 耱痼牝箴眍 镥疱戾眄铋, 玎觌屙 翳泱痦 耜钺觇 疣玟咫屙 玎螓扈 (镥疴 桤 忮腓麒 镳桉忄桠噱蝰 镥疴铎 镱膻, 怛铕 - 怛铕铎 镱膻 . .)

枢 忤滂, 祛骓 镳桉忄桠囹 珥圜屙桢 钿眍 耱痼牝箴眍 镥疱戾眄铋 漯筱铋 耱痼牝箴眍 镥疱戾眄铋: part2 = part1;琼圜屙桢 赅驿钽 镱 镥疱戾眄铋 part1 镳桉忄桠噱蝰 耦铗忮蝰蜮簋祗 镱膻 镥疱戾眄铋 part2. 马桁囗桢: 铒屦圉 镳桉忄桠囗 祛驽 猁螯 恹镱腠屙 蝾朦觐 磬 镥疱戾眄, 桁妣扈 钿桧 蝾 驽 蜩.

囗汶栝耜铋 耔耱屐 戾 铖眍忭 邃桧桷囔 桤戾疱龛 潆桧 耠箧囹 趔 濑殪, 镳梓屐 钿桧 趔 疣忮 12 濑殪囔. 橡邃镱腩骅, 礤钺躅滂祛 耦玟囹 桧驽礤痦 镳铄牝 桉镱朦珙忄龛屐 囗汶栝耜铋 耔耱屐 戾.

聋腩 猁 箐钺眍 镳邃耱噔螯 潆桧 忤溴 溻篚 麒皴, 钿眍 桤 觐蝾瘥 疣忭腩顸 猁 觐腓麇耱怏 趔蝾, 漯筱铄 - 觐腓麇耱怏 濑殪钼. 耠邃簋 镳桁屦  桎 疱嚯桤钼囗 镱祛 耱痼牝箴.

#include <iostream>

using namespace std;

struct Mera牋牋 // 潆桧 囗汶栝耜铋 耔耱屐

{

int fut; float dujm;

};

橡桁屦 镳桁屙屙 耱痼牝箴

int main()

{

Mera d1, d3;

Mera d2 = { 11, 6.25 };

cout << 揬n骡邃栩 麒耠 趔蝾: "; cin >> d1.fut;

cout << "骡邃栩 麒耠 濑殪钼: ": cin >> d1.dujm;

d3.dujm = d1.dujm +d2.dujm;

d3.fut =0;

if ( d3.dujm >= 12.0 )

{

d3.dujm -= 12.0; d3.fut++;

}

d3.fut += d1.fut + d2.fut;

cout << d1.fut <<"\'-" << d1.dujm << "\" + ";

cout << d2.fut <<"\-" << d2.dujm << "\" = ";

cout << d3.fut <<"\'-" << d3.dujm << "\"\n";

return 0;

}

橡桁屦 镳桁屙屙 耱痼牝箴

卿羼 耱痼牝箴 Mera 耦耱铊 桤 溻篚 镱脲: fut dujm. 物疱溴脲睇 蝠 镥疱戾眄 蜩镟 Mera: d1, d2 d3, 镳梓屐 镥疱戾眄簋 d2 桧桷栲腓玷痤忄腓 珥圜屙桢 11-6.25", 镥疱戾眄 d1 d3 镱赅 铖蜞怆屙 徨 磬鬣朦眍泐 珥圜屙. 青蝈 镳钽疣祆 玎镳帏桠噱 镱朦珙忄蝈 麒耠 趔蝾 濑殪钼, 觐蝾瘥 桉镱朦珞 潆 桧桷栲腓玎鲨 镥疱戾眄铋 d1. 青蝈 珥圜屙 d1 d2 耜豚潲忄, 疱珞朦蜞 镳桉忄桠噱蝰 镥疱戾眄铋 d3. 袜觐礤, 镳钽疣祆 恹忸滂 溻 镥疴铐圜嚯 潆桧 桴 耋祆. 马桁囗桢: 礤朦 耠铈栩 溻 潆桧 耠邃簋 钺疣珙:

d3 = d1 + d2;

亦觐 溴轳蜮桢 恹珙忮 铠栳牦, C++ 礤 铒疱溴脲睇 溴轳蜮, 觐蝾瘥 礤钺躅滂祛 恹镱腠栩 镳 耠铈屙梃 镥疱戾眄 蜩镟 Mera. 物屦圉 + 镳桁屙桁 潆 耱囗溧痱睇 蜩镱 C++, 眍 铐 礤 铒疱溴脲磬 潆 蜩镱 溧眄, 觐蝾瘥 耦玟帼蝰 镱朦珙忄蝈扈 ().

牋牋牋牋牋牋 羊痼牝箴 觌囫覃

袜漕 铗戾蜩螯, 黩 耩噔龛忄螯 戾驿 耦犷 耱痼牝箴睇 镥疱戾眄, 赅 耜豚潲忄螯 桴 漯筱 漯筱铎, 礤朦. 袜镳桁屦, 潆 耱痼牝箴睇 镥疱戾眄 part1 part2 蜩镟 part, 觐眈蝠箨鲨 if (part1 == part2) 礤漕矬耱桁, 镱蝾祗 黩 铒屦圉梃 == 龛麇泐 桤忮耱眍 镥疱戾眄 蜩镟 part. 武磬觐, 赅 禧 筲桎桁 镱珂, 溧眄 镳钺脲爨 疣琊屮桁 镱祛 镥疱沭箸觇 铒屦圉栝. 枢 桤忮耱眍, 耱痼牝箴 钺眍 桉镱朦珞 潆 钺滂礤龛 溧眄, 觌囫覃 - 潆 钺滂礤龛 溧眄 趔黻鲨.

义 礤 戾礤, C++ 耱痼牝箴 蜞赕 钺豚溧 忸珈铈眍耱 怅膻鬣螯 皴 趔黻鲨. 朽珉梓 耔眚嚓耔皴 戾驿 耱痼牝箴囔 觌囫襦扈 扈龛爨朦睇, 镱铎 蝈铕弪梓羼觇 祛骓 桉镱朦珙忄螯 钿眍 忪羼蝾 漯筱钽. 武磬觐 耱痼牝箴 钺眍 桉镱朦珞 蝾朦觐 潆 躔囗屙 溧眄, 觌囫覃 - 潆 躔囗屙 溧眄 趔黻鲨. 橡铊玮钿蝰 祉钽桢 溴轳蜮 琨赅 C++. 吾羼镥麒忄 漕耱箫 羿殡囔, 镳铊玮钿 爨蝈爨蜩麇耜桢 疣聍弪, 恹镱腠 镳孱狃噻钼囗桢 溧眄 漯. 溴轳蜮.

橡桁屦 桉镱朦珙忄龛 徼犭桀蝈黜铋 趔黻鲨 sqrt

#include <iostream.h>

#include <cmath.h>

using namespace std;

int main()

{

double num,answ;

cout << "骡邃栩 麒耠: ";

cin >> num;

answ = sqrt(numr);

cout << "殊噤疣蝽 觐疱睃 疣忮 " << answ << endl;牋牋牋牋牋牋牋牋牋 return 0;

}牋牋

秧圜嚯 镳钽疣祆 镱塍鬣弪 珥圜屙桢 铗 镱朦珙忄蝈. 青蝈 镱塍麇眄铄 珥圜屙桢 桉镱朦珞弪 赅麇耱忮 囵泱戾眚 潆 趔黻鲨 sqrt(): answ = sqrt(number); 泽黻鲨 钺疣徉螓忄弪 囵泱戾眚 忸玮疣弪 珥圜屙桢 - 恹躅漤 溧眄 趔黻鲨. 骂玮疣龛 珥圜屙 趔黻鲨彘 铉磬鬣弪 忸珈铈眍耱 镳桉忄桠囗 蜞觐泐 珥圜屙 镥疱戾眄铋 耦铗忮蝰蜮簋泐 蜩镟, 溧眄铎 耠篦噱 - 镥疱戾眄铋 answ. 青蝈 镳钽疣祆 铗钺疣驵弪 珥圜屙桢 镥疱戾眄铋 磬 疣礤. 鲤泱戾眚 趔黻鲨 忸玮疣屐 桁 珥圜屙 漕腈睇 桁弪 镳噔桦 蜩. 软纛痨圉棹 钺 桴 蜩镟 祛骓 镱塍麒螯 镱祛 耧疣忸黜铋 耔耱屐 觐祜桦蝾疣, 耦溴疰帙彘 铒桉囗 徼犭桀蝈黜 趔黻鲨. 碾 趔黻鲨 sqrt() 囵泱戾眚, 忸玮疣屐铄 珥圜屙桢 漕腈睇 桁弪 蜩 double, 镱铎 镳钽疣祆 桉镱朦珙忄睇 镥疱戾眄 桁屙眍 钽 蜩镟.