0% found this document useful (0 votes)
8 views

C++: 100 Simple Codes

The document contains a collection of C++ programming examples covering various fundamental concepts such as input/output, control structures, functions, recursion, classes, and arrays. Each example is presented with a brief description and corresponding code snippet. The examples range from basic operations like printing 'Hello, World!' to more complex tasks like implementing classes and recursive functions.

Uploaded by

Souhail Laghchim
Copyright
© Public Domain
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

C++: 100 Simple Codes

The document contains a collection of C++ programming examples covering various fundamental concepts such as input/output, control structures, functions, recursion, classes, and arrays. Each example is presented with a brief description and corresponding code snippet. The examples range from basic operations like printing 'Hello, World!' to more complex tasks like implementing classes and recursive functions.

Uploaded by

Souhail Laghchim
Copyright
© Public Domain
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

1.

Hello World
C++:

#include <iostream>
int main() {
std::cout << "Hello, World!";
return 0;
}

2. Add Two Numbers


C++:

#include <iostream>
int main() {
int a = 5, b = 3;
std::cout << a + b;
return 0;
}

3. Input and Output


C++:

#include <iostream>
int main() {
int x;
std::cin >> x;
std::cout << "You entered: " << x;
return 0;
}

4. Check Even or Odd


C++:

#include <iostream>
int main() {
int num;
std::cin >> num;
if (num % 2 == 0)
std::cout << "Even";
else
std::cout << "Odd";
return 0;
}
5. Find Maximum of Two Numbers
C++:

#include <iostream>
int main() {
int a, b;
std::cin >> a >> b;
std::cout << ((a > b) ? a : b);
return 0;
}

6. Simple Calculator (Addition)


C++:

#include <iostream>
int main() {
float a, b;
std::cin >> a >> b;
std::cout << "Sum = " << a + b;
return 0;
}

7. Swap Two Numbers


C++:

#include <iostream>
int main() {
int a = 10, b = 20, temp;
temp = a;
a = b;
b = temp;
std::cout << a << " " << b;
return 0;
}
8. Check Positive or Negative
C++:

#include <iostream>
int main() {
int num;
std::cin >> num;
if (num >= 0)
std::cout << "Positive";
else
std::cout << "Negative";
return 0;
}

9. Simple For Loop


C++:

#include <iostream>
int main() {
for (int i = 1; i <= 5; i++)
std::cout << i << " ";
return 0;
}

10. Print Multiplication Table


C++:

#include <iostream>
int main() {
int n;
std::cin >> n;
for (int i = 1; i <= 10; i++)
std::cout << n << " x " << i << " = " << n * i << "\n";
return 0;
}
11. Sum of First N Natural Numbers
C++:

#include <iostream>
int main() {
int n, sum = 0;
std::cin >> n;
for (int i = 1; i <= n; i++)
sum += i;
std::cout << "Sum = " << sum;
return 0;
}

12. Factorial of a Number


C++:

#include <iostream>
int main() {
int n, fact = 1;
std::cin >> n;
for (int i = 1; i <= n; i++)
fact *= i;
std::cout << "Factorial = " << fact;
return 0;
}

13. Check Leap Year


C++:

#include <iostream>
int main() {
int year;
std::cin >> year;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
std::cout << "Leap Year";
else
std::cout << "Not a Leap Year";
return 0;
}
14. Print ASCII Value of Character
C++:

#include <iostream>
int main() {
char ch;
std::cin >> ch;
std::cout << "ASCII = " << int(ch);
return 0;
}

15. Simple While Loop


C++:

#include <iostream>
int main() {
int i = 1;
while (i <= 5) {
std::cout << i << " ";
i++;
}
return 0;
}

16. Print Fibonacci Series


C++:

#include <iostream>
int main() {
int n, a = 0, b = 1;
std::cin >> n;
for (int i = 0; i < n; i++) {
std::cout << a << " ";
int next = a + b;
a = b;
b = next;
}
return 0;
}
17. Check Prime Number
C++:

#include <iostream>
int main() {
int n, i, flag = 0;
std::cin >> n;
if (n <= 1) flag = 1;
for (i = 2; i <= n / 2; i++) {
if (n % i == 0) {
flag = 1;
break;
}
}
std::cout << (flag ? "Not Prime" : "Prime");
return 0;
}

18. Power of a Number


C++:

#include <iostream>
#include <cmath>
int main() {
int base, exp;
std::cin >> base >> exp;
std::cout << pow(base, exp);
return 0;
}

19. Simple Do-While Loop


C++:

#include <iostream>
int main() {
int i = 1;
do {
std::cout << i << " ";
i++;
} while (i <= 5);
return 0;
}
20. Find GCD of Two Numbers
C++:

#include <iostream>
int main() {
int a, b;
std::cin >> a >> b;
while (a != b) {
if (a > b)
a -= b;
else
b -= a;
}
std::cout << "GCD = " << a;
return 0;
}
21. Find LCM of Two Numbers
C++:

#include <iostream>
int main() {
int a, b, max;
std::cin >> a >> b;
max = (a > b) ? a : b;
while (true) {
if (max % a == 0 && max % b == 0) {
std::cout << "LCM = " << max;
break;
}
max++;
}
return 0;
}

22. Count Number of Digits


C++:

#include <iostream>
int main() {
int n, count = 0;
std::cin >> n;
while (n != 0) {
n /= 10;
count++;
}
std::cout << "Digits = " << count;
return 0;
}
23. Reverse a Number
C++:

#include <iostream>
int main() {
int n, rev = 0;
std::cin >> n;
while (n != 0) {
rev = rev * 10 + n % 10;
n /= 10;
}
std::cout << "Reversed = " << rev;
return 0;
}

24. Check Palindrome Number


C++:

#include <iostream>
int main() {
int n, rev = 0, temp;
std::cin >> n;
temp = n;
while (n != 0) {
rev = rev * 10 + n % 10;
n /= 10;
}
std::cout << (temp == rev ? "Palindrome" : "Not Palindrome");
return 0;
}
25. Check Armstrong Number (3-digit)
C++:

#include <iostream>
#include <cmath>
int main() {
int n, sum = 0, temp, digit;
std::cin >> n;
temp = n;
while (n != 0) {
digit = n % 10;
sum += pow(digit, 3);
n /= 10;
}
std::cout << (temp == sum ? "Armstrong" : "Not Armstrong");
return 0;
}

26. Sum of Digits


C++:

#include <iostream>
int main() {
int n, sum = 0;
std::cin >> n;
while (n != 0) {
sum += n % 10;
n /= 10;
}
std::cout << "Sum = " << sum;
return 0;
}

27. Find Largest Among Three Numbers


C++:

#include <iostream>
int main() {
int a, b, c;
std::cin >> a >> b >> c;
int max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
std::cout << "Max = " << max;
return 0;
}
28. Simple Menu Using Switch Case
C++:

#include <iostream>
int main() {
int choice;
std::cout << "1. Hello\n2. Bye\nChoice: ";
std::cin >> choice;
switch (choice) {
case 1: std::cout << "Hello"; break;
case 2: std::cout << "Bye"; break;
default: std::cout << "Invalid";
}
return 0;
}

29. Check Vowel or Consonant


C++:

#include <iostream>
int main() {
char ch;
std::cin >> ch;
ch = tolower(ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
std::cout << "Vowel";
else
std::cout << "Consonant";
return 0;
}

30. Simple Pattern: Star Triangle


C++:

#include <iostream>
int main() {
int n;
std::cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
std::cout << "*";
std::cout << "\n";
}
return 0;
}
31. Number Pyramid Pattern
C++:

#include <iostream>
int main() {
int n;
std::cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
std::cout << j << " ";
std::cout << "\n";
}
return 0;
}

32. Print Alphabets from A to Z


C++:

#include <iostream>
int main() {
for (char c = 'A'; c <= 'Z'; c++)
std::cout << c << " ";
return 0;
}

33. Find Sum and Average of Array


C++:

#include <iostream>
int main() {
int a[5] = {1, 2, 3, 4, 5}, sum = 0;
for (int i = 0; i < 5; i++)
sum += a[i];
std::cout << "Sum = " << sum << ", Avg = " << sum / 5.0;
return 0;
}
34. Linear Search in Array
C++:

#include <iostream>
int main() {
int a[5] = {2, 4, 6, 8, 10}, key;
std::cin >> key;
bool found = false;
for (int i = 0; i < 5; i++) {
if (a[i] == key) {
found = true;
break;
}
}
std::cout << (found ? "Found" : "Not Found");
return 0;
}

35. Find Maximum in Array


C++:

#include <iostream>
int main() {
int a[5] = {5, 7, 2, 9, 1}, max = a[0];
for (int i = 1; i < 5; i++)
if (a[i] > max) max = a[i];
std::cout << "Max = " << max;
return 0;
}

36. Simple Bubble Sort


C++:

#include <iostream>
int main() {
int a[5] = {4, 2, 5, 1, 3};
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4 - i; j++)
if (a[j] > a[j + 1])
std::swap(a[j], a[j + 1]);
for (int i = 0; i < 5; i++)
std::cout << a[i] << " ";
return 0;
}
37. 2D Array Input and Output
C++:

#include <iostream>
int main() {
int a[2][2];
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
std::cin >> a[i][j];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++)
std::cout << a[i][j] << " ";
std::cout << "\n";
}
return 0;
}

38. Transpose of Matrix


C++:

#include <iostream>
int main() {
int a[2][2] = {{1, 2}, {3, 4}};
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++)
std::cout << a[j][i] << " ";
std::cout << "\n";
}
return 0;
}

39. Simple Function Example


C++:

#include <iostream>
void greet() {
std::cout << "Hello from function!";
}
int main() {
greet();
return 0;
}
40. Function with Parameters
C++:

#include <iostream>
void add(int a, int b) {
std::cout << "Sum = " << a + b;
}
int main() {
add(4, 5);
return 0;
}
41. Function with Return Value
C++:

#include <iostream>
int square(int x) {
return x * x;
}
int main() {
std::cout << square(5);
return 0;
}

42. Recursive Factorial


C++:

#include <iostream>
int factorial(int n) {
return (n <= 1) ? 1 : n * factorial(n - 1);
}
int main() {
std::cout << factorial(5);
return 0;
}

43. Recursive Fibonacci


C++:

#include <iostream>
int fib(int n) {
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
}
int main() {
for (int i = 0; i < 5; i++)
std::cout << fib(i) << " ";
return 0;
}
44. Create and Use a Class
C++:

#include <iostream>
class Car {
public:
void drive() {
std::cout << "Driving!";
}
};
int main() {
Car c;
c.drive();
return 0;
}

45. Class with Constructor


C++:

#include <iostream>
class Person {
public:
Person() {
std::cout << "Constructor called!";
}
};
int main() {
Person p;
return 0;
}

46. Class with Parameters in Constructor


C++:

#include <iostream>
class Person {
public:
Person(std::string name) {
std::cout << "Hello, " << name;
}
};
int main() {
Person p("Souhail");
return 0;
}
47. Class with Member Variables
C++:

#include <iostream>
class Rectangle {
public:
int width, height;
int area() {
return width * height;
}
};
int main() {
Rectangle r;
r.width = 4;
r.height = 5;
std::cout << "Area = " << r.area();
return 0;
}

48. Array of Objects


C++:

#include <iostream>
class Student {
public:
std::string name;
void show() {
std::cout << "Name: " << name << "\n";
}
};
int main() {
Student s[2];
s[0].name = "Ali";
s[1].name = "Lina";
s[0].show();
s[1].show();
return 0;
}
49. Simple Inheritance
C++:

#include <iostream>
class Animal {
public:
void speak() {
std::cout << "Animal sound\n";
}
};
class Dog : public Animal {
public:
void bark() {
std::cout << "Dog barks\n";
}
};
int main() {
Dog d;
d.speak();
d.bark();
return 0;
}

50. Method Overloading


C++:

#include <iostream>
class Math {
public:
int add(int a, int b) { return a + b; }
float add(float a, float b) { return a + b; }
};
int main() {
Math m;
std::cout << m.add(3, 4) << "\n";
std::cout << m.add(3.5f, 2.5f);
return 0;
}
51. Simple Friend Function
C++:

#include <iostream>
class Box {
private:
int width;
public:
Box() { width = 10; }
friend void printWidth(Box b);
};
void printWidth(Box b) {
std::cout << "Width: " << b.width;
}
int main() {
Box b;
printWidth(b);
return 0;
}

52. Static Variable in Function


C++:

#include <iostream>
void counter() {
static int count = 0;
count++;
std::cout << "Count: " << count << "\n";
}
int main() {
counter();
counter();
counter();
return 0;
}
53. Inline Function
C++:

#include <iostream>
inline int cube(int x) {
return x * x * x;
}
int main() {
std::cout << cube(3);
return 0;
}

54. Default Argument in Function


C++:

#include <iostream>
int add(int a, int b = 5) {
return a + b;
}
int main() {
std::cout << add(10) << "\n";
std::cout << add(10, 20);
return 0;
}

55. Simple Pointer Example


C++:

#include <iostream>
int main() {
int x = 10;
int* ptr = &x;
std::cout << "Value: " << *ptr;
return 0;
}
56. Swap Using Pointers
C++:

#include <iostream>
void swap(int* a, int* b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int x = 5, y = 10;
swap(&x, &y);
std::cout << x << " " << y;
return 0;
}

57. Pointer to Array


C++:

#include <iostream>
int main() {
int arr[3] = {10, 20, 30};
int* p = arr;
for (int i = 0; i < 3; i++)
std::cout << *(p + i) << " ";
return 0;
}

58. Dynamic Memory Allocation


C++:

#include <iostream>
int main() {
int* p = new int(25);
std::cout << *p;
delete p;
return 0;
}
59. Simple String Input/Output
C++:

#include <iostream>
#include <string>
int main() {
std::string name;
std::getline(std::cin, name);
std::cout << "Hello, " << name;
return 0;
}

60. String Length


C++:

#include <iostream>
#include <string>
int main() {
std::string txt = "C++ Programming";
std::cout << "Length: " << txt.length();
return 0;
}
61. Reverse a String
C++:

#include <iostream>
#include <string>
#include <algorithm>
int main() {
std::string text = "hello";
std::reverse(text.begin(), text.end());
std::cout << text;
return 0;
}

62. Check Palindrome String


C++:

#include <iostream>
#include <string>
#include <algorithm>
int main() {
std::string s;
std::cin >> s;
std::string rev = s;
std::reverse(rev.begin(), rev.end());
std::cout << (s == rev ? "Palindrome" : "Not Palindrome");
return 0;
}

63. Concatenate Strings


C++:

#include <iostream>
#include <string>
int main() {
std::string a = "Hello", b = " World";
std::string c = a + b;
std::cout << c;
return 0;
}
64. Compare Two Strings
C++:

#include <iostream>
#include <string>
int main() {
std::string a = "apple", b = "banana";
if (a == b)
std::cout << "Equal";
else
std::cout << "Not Equal";
return 0;
}

65. Count Words in a String


C++:

#include <iostream>
#include <sstream>
#include <string>
int main() {
std::string line;
std::getline(std::cin, line);
std::stringstream ss(line);
std::string word;
int count = 0;
while (ss >> word) count++;
std::cout << "Words: " << count;
return 0;
}

66. Using getline to Read Full Line


C++:

#include <iostream>
#include <string>
int main() {
std::string input;
std::getline(std::cin, input);
std::cout << "You typed: " << input;
return 0;
}
67. Count Vowels in a String
C++:

#include <iostream>
#include <string>
int main() {
std::string str;
std::getline(std::cin, str);
int count = 0;
for (char c : str) {
c = tolower(c);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
count++;
}
std::cout << "Vowels: " << count;
return 0;
}

68. Check if Character is Digit


C++:

#include <iostream>
int main() {
char c;
std::cin >> c;
std::cout << (isdigit(c) ? "Digit" : "Not a digit");
return 0;
}

69. Check if Character is Alphabet


C++:

#include <iostream>
int main() {
char c;
std::cin >> c;
std::cout << (isalpha(c) ? "Alphabet" : "Not alphabet");
return 0;
}
70. Uppercase and Lowercase Conversion
C++:

#include <iostream>
#include <cctype>
int main() {
char c;
std::cin >> c;
std::cout << "Upper: " << (char)toupper(c) << "\n";
std::cout << "Lower: " << (char)tolower(c);
return 0;
}
71. Count Digits in Number
C++:

#include <iostream>
int main() {
int n, count = 0;
std::cin >> n;
while (n != 0) {
count++;
n /= 10;
}
std::cout << "Digits: " << count;
return 0;
}

72. Sum of Digits


C++:

#include <iostream>
int main() {
int n, sum = 0;
std::cin >> n;
while (n != 0) {
sum += n % 10;
n /= 10;
}
std::cout << "Sum: " << sum;
return 0;
}

73. Reverse Digits of Number


C++:

#include <iostream>
int main() {
int n, rev = 0;
std::cin >> n;
while (n != 0) {
rev = rev * 10 + n % 10;
n /= 10;
}
std::cout << "Reversed: " << rev;
return 0;
}
74. Check Armstrong Number (3-digit)
C++:

#include <iostream>
int main() {
int n, original, sum = 0;
std::cin >> n;
original = n;
while (n != 0) {
int digit = n % 10;
sum += digit * digit * digit;
n /= 10;
}
std::cout << (sum == original ? "Armstrong" : "Not Armstrong");
return 0;
}

75. Check Perfect Number


C++:

#include <iostream>
int main() {
int n, sum = 0;
std::cin >> n;
for (int i = 1; i < n; i++)
if (n % i == 0) sum += i;
std::cout << (sum == n ? "Perfect" : "Not Perfect");
return 0;
}

76. Sum of First N Natural Numbers (Formula)


C++:

#include <iostream>
int main() {
int n;
std::cin >> n;
std::cout << "Sum: " << n * (n + 1) / 2;
return 0;
}
77. Power of a Number
C++:

#include <iostream>
#include <cmath>
int main() {
int base, exp;
std::cin >> base >> exp;
std::cout << pow(base, exp);
return 0;
}

78. Check if Even or Odd using Bitwise


C++:

#include <iostream>
int main() {
int n;
std::cin >> n;
std::cout << ((n & 1) ? "Odd" : "Even");
return 0;
}

79. Swap Numbers using XOR


C++:

#include <iostream>
int main() {
int a = 5, b = 10;
a ^= b;
b ^= a;
a ^= b;
std::cout << a << " " << b;
return 0;
}
80. Calculate LCM (Lowest Common Multiple)
C++:

#include <iostream>
int main() {
int a, b, lcm;
std::cin >> a >> b;
lcm = (a > b) ? a : b;
while (true) {
if (lcm % a == 0 && lcm % b == 0) break;
lcm++;
}
std::cout << "LCM: " << lcm;
return 0;
}
81. Calculate GCD (Greatest Common Divisor)
C++:

#include <iostream>
int gcd(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
int main() {
int a, b;
std::cin >> a >> b;
std::cout << "GCD: " << gcd(a, b);
return 0;
}

82. Generate Random Number


C++:

#include <iostream>
#include <cstdlib>
#include <ctime>
int main() {
std::srand(std::time(0));
std::cout << "Random: " << rand() % 100;
return 0;
}
83. Simple Calculator (switch case)
C++:

#include <iostream>
int main() {
char op;
float a, b;
std::cin >> a >> op >> b;
switch (op) {
case '+': std::cout << a + b; break;
case '-': std::cout << a - b; break;
case '*': std::cout << a * b; break;
case '/': std::cout << a / b; break;
default: std::cout << "Invalid operator";
}
return 0;
}

84. Check Leap Year


C++:

#include <iostream>
int main() {
int year;
std::cin >> year;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
std::cout << "Leap Year";
else
std::cout << "Not Leap Year";
return 0;
}

85. Check Prime Number


C++:

#include <iostream>
int main() {
int n, isPrime = 1;
std::cin >> n;
if (n <= 1) isPrime = 0;
for (int i = 2; i <= n / 2; i++)
if (n % i == 0) isPrime = 0;
std::cout << (isPrime ? "Prime" : "Not Prime");
return 0;
}
86. Print Prime Numbers in Range
C++:

#include <iostream>
int isPrime(int n) {
if (n <= 1) return 0;
for (int i = 2; i <= n / 2; i++)
if (n % i == 0) return 0;
return 1;
}
int main() {
for (int i = 1; i <= 20; i++)
if (isPrime(i)) std::cout << i << " ";
return 0;
}

87. Find Max of 3 Numbers


C++:

#include <iostream>
int main() {
int a, b, c;
std::cin >> a >> b >> c;
int max = (a > b) ? (a > c ? a : c) : (b > c ? b : c);
std::cout << "Max: " << max;
return 0;
}

88. Simple Login System


C++:

#include <iostream>
#include <string>
int main() {
std::string user, pass;
std::cin >> user >> pass;
if (user == "admin" && pass == "1234")
std::cout << "Access Granted";
else
std::cout << "Access Denied";
return 0;
}
89. Ternary Operator Example
C++:

#include <iostream>
int main() {
int a, b;
std::cin >> a >> b;
int max = (a > b) ? a : b;
std::cout << "Max: " << max;
return 0;
}

90. Print ASCII Value of Character


C++:

#include <iostream>
int main() {
char c;
std::cin >> c;
std::cout << "ASCII: " << (int)c;
return 0;
}
91. Convert Celsius to Fahrenheit
C++:

#include <iostream>
int main() {
float c;
std::cin >> c;
float f = (c * 9 / 5) + 32;
std::cout << "Fahrenheit: " << f;
return 0;
}

92. Calculate Area of Circle


C++:

#include <iostream>
const float PI = 3.14159;
int main() {
float r;
std::cin >> r;
std::cout << "Area: " << PI * r * r;
return 0;
}

93. Calculate Circumference of Circle


C++:

#include <iostream>
const float PI = 3.14159;
int main() {
float r;
std::cin >> r;
std::cout << "Circumference: " << 2 * PI * r;
return 0;
}
94. Calculate Area of Triangle
C++:

#include <iostream>
int main() {
float base, height;
std::cin >> base >> height;
std::cout << "Area: " << 0.5 * base * height;
return 0;
}

95. Calculate Simple Interest


C++:

#include <iostream>
int main() {
float p, r, t;
std::cin >> p >> r >> t;
std::cout << "Simple Interest: " << (p * r * t) / 100;
return 0;
}

96. Calculate Compound Interest


C++:

#include <iostream>
#include <cmath>
int main() {
double p, r, t, ci;
std::cin >> p >> r >> t;
ci = p * pow((1 + r / 100), t) - p;
std::cout << "Compound Interest: " << ci;
return 0;
}
97. Check if Number is Positive, Negative or Zero
C++:

#include <iostream>
int main() {
int n;
std::cin >> n;
if (n > 0)
std::cout << "Positive";
else if (n < 0)
std::cout << "Negative";
else
std::cout << "Zero";
return 0;
}

98. Calculate Factorial Using Iteration


C++:

#include <iostream>
int main() {
int n;
unsigned long long fact = 1;
std::cin >> n;
for (int i = 1; i <= n; ++i)
fact *= i;
std::cout << "Factorial: " << fact;
return 0;
}

99. Print ASCII Characters from 65 to 90


C++:

#include <iostream>
int main() {
for (int i = 65; i <= 90; ++i)
std::cout << (char)i << " ";
return 0;
}
100. Calculate Sum of Array Elements
C++:

#include <iostream>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int sum = 0;
for (int i = 0; i < 5; ++i)
sum += arr[i];
std::cout << "Sum: " << sum;
return 0;
}

Email:
[email protected]

Blogger:
https://souhaillaghchimdev.blogspot.com/

You might also like