Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++
C++
  1. โปรแกรม C++ หาค่าสูงสุด (Largest Element) ในอาร์เรย์

    หาตัวเลขที่มากที่สุดในอาร์เรย์และตำแหน่ง index ของมัน ตัวอย่าง: [5, 1, 7, 2, 4] → มากที่สุดคือ 7 อยู่ index 2 ตัวอย่างโค้ด largest) { largest = a[i]; pos = i; } } cout << The largest element in the array is << largest << and it is at inde

  2. โปรแกรม C++ แสดงจำนวนเฉพาะระหว่างสองช่วง (เวอร์ชัน 2)

    1 ที่หารได้แค่ 1 และตัวเอง: 2, 3, 5, 7, 11, 13, 17... จำนวนเฉพาะระหว่าง 5-20: 5, 7, 11, 13, 17, 19 ตัวอย่างโค้ด #include <iostream> using namespace std; void PrimeNumbers(int lbound, int ubound) { int flag, i; while (lbound <= ubound) { flag = 0; for(i = 2; i <

  3. โปรแกรม C++ แสดงเลขอาร์มสตรอง (Armstrong Numbers) ระหว่างสองช่วง

    Armstrong Number คือเลขที่ผลรวมของแต่ละหลักยกกำลังจำนวนหลัก = เลขเดิม ตัวอย่าง: 3 = 3^1 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 407 = 4^3 + 0^3 + 7^3 = 64 + 0 + 343 = 407 1634 = 1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634 ตัวอย่างโค้ด #include <iostream> #include <cmath> using

  4. โปรแกรม C++ แสดงจำนวนเฉพาะ (Prime Numbers) ระหว่างสองช่วงด้วยฟังก์ชัน

    1 ที่มีตัวหารได้แค่ 1 และตัวมันเอง ตัวอย่าง: 2, 3, 5, 7, 11, 13, 17... จำนวนเฉพาะระหว่าง 5-20: 5, 7, 11, 13, 17, 19 ตัวอย่างโค้ด #include <iostream> using namespace std; void primeNumbers(int lbound, int ubound) { int flag, i; while (lbound <= ubound) { flag = 0;

  5. โปรแกรม C++ คำนวณค่าเฉลี่ย (Average) ของตัวเลขในอาร์เรย์

    ค่าเฉลี่ย = ผลรวมตัวเลขทั้งหมด ÷ จำนวนตัวเลข ตัวอย่าง: 10, 5, 32, 4, 9 → Sum = 60, Average = 60/5 = 12 ตัวอย่างโค้ด #include <iostream> using namespace std; int main() { int n, i; float sum = 0.0, avg; float num[] = {12, 76, 23, 9, 5}; n = sizeof(num) / sizeof(num[0]); fo

  6. โปรแกรม C++ หา Transpose ของเมทริกซ์

    Transpose ของเมทริกซ์ คือเมทริกซ์ใหม่ที่แถวกลายเป็นคอลัมน์ และคอลัมน์กลายเป็นแถว ตัวอย่าง เมทริกซ์ 3×2: 1 2 3 4 5 6 Transpose (2×3): 1 3 5 2 4 6 ตัวอย่างโค้ด #include <iostream> using namespace std; int main() { int transpose[10][10], r=3, c=2, i, j; int a[3][3] = { {1, 2}, {3, 4}, {

  7. โปรแกรม C++ หาความยาวสตริง (String Length)

    ความยาวสตริง = จำนวนตัวอักษรก่อน null character (\0) ตัวอย่าง: The sky is blue มี 15 ตัวอักษร วิธี 1: ใช้ while loop นับเอง #include <iostream> using namespace std; int main() { char str[] = Apple; int count = 0; while (str[count] != \0) count++; cout << The str

  8. โปรแกรม C++ นับสระ พยัญชนะ ตัวเลข และช่องว่างในสตริง

    String อาจมีสระ พยัญชนะ ตัวเลข ช่องว่าง โปรแกรมนี้นับจำนวนแต่ละประเภท ตัวอย่าง: There are 7 colours in the rainbow → สระ 12, พยัญชนะ 15, ตัวเลข 1, ช่องว่าง 6 ตัวอย่างโค้ด =a && str[i]=A && str[i]=0 && str[i]<=9) { ++digits; } else if (str[i]== ) { ++spaces; }

  9. โปรแกรม C++ จัดเก็บข้อมูลนักเรียนด้วย Structure

    Structure รวมข้อมูลหลายชนิด ใช้คีย์เวิร์ด struct เหมาะสำหรับข้อมูลนักเรียน ตัวอย่างโครงสร้างพนักงาน: struct employee { int empID; char name[50]; float salary; }; ตัวอย่างโค้ด (ข้อมูลนักเรียน) #include <iostream> using namespace std; struct student { int rollNo; char name[

  10. โปรแกรม C++ เข้าถึงสมาชิกอาร์เรย์ด้วย Pointer

    Pointer เก็บที่อยู่หน่วยความจำของตัวแปร Dereference pointer คือการดึงค่าที่อยู่ที่นั่น ตัวอย่าง 1: เข้าถึงสมาชิกเดี่ยว #include <iostream> using namespace std; int main() { int arr[5] = {5, 2, 9, 4, 1}; int *ptr = &arr[2]; cout << The value in the second index of the ar

  11. โปรแกรม C++ แปลงเลขฐานแปด (Octal) ↔ ฐานสิบ (Decimal) ทั้งสองทาง

    เลขฐานแปด (Octal) ใช้ฐาน 8 เลขฐานสิบ (Decimal) ใช้ฐาน 10 ตัวอย่างการแปลง: DecimalOctal 1012 70106 2531 1620 ตัวอย่างโค้ด (แปลงทั้ง 2 ทิศทาง) #include <iostream> #include <cmath> using namespace std; void DecimalToOctal(int decimalNum) { int octalNum = 0, placeValue = 1; int

Total 6007 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:17/301  20-คอมพิวเตอร์/Page Goto:1 11 12 13 14 15 16 17 18 19 20 21 22 23