├── A simple calculator
├── Readme.md
└── Calculator.cpp
├── Pointers
├── Readme.md
└── P.cpp
├── Data types in C++
└── IMG_20230815_115242.jpg
├── C++ math library functions
└── IMG_20230815_115942.jpg
├── README.md
├── Print odd numbers
└── Oddnum.cpp
├── Print even numbers
└── evennum.cpp
├── Triangles
├── Print Triangles using *.cpp
├── Print Triangles using numbers.cpp
├── Print an inverted half-pyramid using *.cpp
├── Print a full pyramid using *.cpp
└── Print a pyramid using numbers.cpp
├── How to make a function
├── function.cpp
└── readme.md
├── FizzBuzz
└── FizzBuzz.cpp
├── Hollow rectangle
└── Hollow rectangle.cpp
├── Fibonacci
└── Fibo.cpp
└── Rectangle
└── Print rectangle using*.cpp
/A simple calculator/Readme.md:
--------------------------------------------------------------------------------
1 | A simple calculator with switch case
2 |
--------------------------------------------------------------------------------
/Pointers/Readme.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Data types in C++/IMG_20230815_115242.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AHGh1386/Cpp-cheatsheet/HEAD/Data types in C++/IMG_20230815_115242.jpg
--------------------------------------------------------------------------------
/C++ math library functions/IMG_20230815_115942.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AHGh1386/Cpp-cheatsheet/HEAD/C++ math library functions/IMG_20230815_115942.jpg
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # C++
2 |
3 |
4 |
5 | In this repository I wanna put some simple C++ codes.
6 |
7 | ### Give star⭐ if it was useful 😉
8 |
--------------------------------------------------------------------------------
/Print odd numbers/Oddnum.cpp:
--------------------------------------------------------------------------------
1 | using namespace std;
2 | #include
3 |
4 | int main() {
5 | int limit;
6 |
7 | cout << "Enter the limit: ";
8 | cin >> limit;
9 |
10 | cout << "Odd numbers from 1 to " << limit << ":" <
3 |
4 | int main() {
5 | int limit;
6 |
7 | cout << "Enter the limit: ";
8 | cin >> limit;
9 |
10 | cout << "Even numbers from 1 to " << limit << ":" << endl;
11 | for (int i = 2; i <= limit; i += 2) {
12 | cout << i << endl;
13 | }
14 |
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/Triangles/Print Triangles using *.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main() {
5 |
6 | int rows;
7 |
8 | cout << "Enter number of rows: ";
9 | cin >> rows;
10 |
11 | for(int i = 1; i <= rows; ++i) {
12 | for(int j = 1; j <= i; ++j) {
13 | cout << "* ";
14 | }
15 | cout << "\n";
16 | }
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/Pointers/P.cpp:
--------------------------------------------------------------------------------
1 | string food = "Pasta"; // A food variable of type string
2 | string* ptr = &food; // A pointer variable, with the name ptr, that stores the address of food
3 |
4 | // Output the value of food (Pasta)
5 | cout << food << "\n";
6 |
7 | // Output the memory address of food
8 | cout << &food << "\n";
9 |
10 | // Output the memory address of food with the pointer
11 | cout << ptr << "\n";
12 |
--------------------------------------------------------------------------------
/Triangles/Print Triangles using numbers.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main() {
5 |
6 | int rows;
7 |
8 | cout << "Enter number of rows: ";
9 | cin >> rows;
10 |
11 | for(int i = 1; i <= rows; ++i) {
12 | for(int j = 1; j <= i; ++j) {
13 | cout << j << " ";
14 | }
15 | cout << "\n";
16 | }
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/How to make a function/function.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | float Plus(int,int);
6 |
7 | int main()
8 | {
9 | int a=10;
10 | float b=35;
11 | Plus(a,b);
12 | std::cout<
2 | using namespace std;
3 |
4 | int main() {
5 |
6 | int rows;
7 |
8 | cout << "Enter number of rows: ";
9 | cin >> rows;
10 |
11 | for(int i = rows; i >= 1; --i) {
12 | for(int j = 1; j <= i; ++j) {
13 | cout << "* ";
14 | }
15 | cout << endl;
16 | }
17 |
18 | return 0;
19 | }
20 |
--------------------------------------------------------------------------------
/FizzBuzz/FizzBuzz.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | for (int i = 1; i <= 100; i++) {
5 | if (i % 3 == 0 && i % 5 == 0) {
6 | std::cout << "FizzBuzz" << std::endl;
7 | } else if (i % 3 == 0) {
8 | std::cout << "Fizz" << std::endl;
9 | } else if (i % 5 == 0) {
10 | std::cout << "Buzz" << std::endl;
11 | } else {
12 | std::cout << i << std::endl;
13 | }
14 | }
15 |
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/How to make a function/readme.md:
--------------------------------------------------------------------------------
1 | int main() is our main funtion.
2 |
3 | So if you wanna make another funtion , you should first write
4 | the type (int , char or etc.) after that you should write the
5 | name of your function. finally write ()
6 |
7 | in () you can put variables and you can send the values to
8 | them with another function.
9 |
10 | For example in my code i made a function that its name is plus.
11 | I sent two variables to it and then it returned a+b in one
12 | variable. finally i can cout and see the result.
13 |
--------------------------------------------------------------------------------
/Triangles/Print a full pyramid using *.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main() {
5 |
6 | int space, rows;
7 |
8 | cout <<"Enter number of rows: ";
9 | cin >> rows;
10 |
11 | for(int i = 1, k = 0; i <= rows; ++i, k = 0) {
12 | for(space = 1; space <= rows-i; ++space) {
13 | cout <<" ";
14 | }
15 |
16 | while(k != 2*i-1) {
17 | cout << "* ";
18 | ++k;
19 | }
20 | cout << endl;
21 | }
22 | return 0;
23 | }
24 |
--------------------------------------------------------------------------------
/Hollow rectangle/Hollow rectangle.cpp:
--------------------------------------------------------------------------------
1 | using namespace std;
2 |
3 | void print_rectangle(int n, int m)
4 | {
5 | int i, j;
6 | for (i = 1; i <= n; i++)
7 | {
8 | for (j = 1; j <= m; j++)
9 | {
10 | if (i == 1 || i == n ||
11 | j == 1 || j == m)
12 | cout << "*";
13 | else
14 | cout << " ";
15 | }
16 | cout << endl;
17 | }
18 |
19 | }
20 |
21 |
22 | int main()
23 | {
24 | int rows = 6, columns = 20;
25 | print_rectangle(rows, columns);
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/Fibonacci/Fibo.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main()
5 | {
6 |
7 | int n, t1 = 0, t2 = 1, nextTerm = 0;
8 |
9 | cout << "Enter the number of terms: ";
10 | cin >> n;
11 |
12 | cout << "Fibonacci Series: ";
13 |
14 | for (int i = 1; i <= n; ++i) {
15 | // Prints the first two terms.
16 | if(i == 1) {
17 | cout << t1 << ", ";
18 | continue;
19 | }
20 | if(i == 2) {
21 | cout << t2 << ", ";
22 | continue;
23 | }
24 | nextTerm = t1 + t2;
25 | t1 = t2;
26 | t2 = nextTerm;
27 |
28 | cout << nextTerm << ", ";
29 | }
30 |
31 | return 0;
32 |
33 | }
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Rectangle/Print rectangle using*.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main()
5 | {
6 | int i, j, rows, columns;
7 | char ch;
8 |
9 | cout << "\nPlease Enter the Total Number of Rectangle Rows = ";
10 | cin >> rows;
11 |
12 | cout << "\nPlease Enter the Total Number of Rectangle Columns = ";
13 | cin >> columns;
14 |
15 | cout << "\nPlease Enter Any Symbol to Print = ";
16 | cin >> ch;
17 |
18 | cout << "\n-----Rectangle Pattern-----\n";
19 | for(i = 1; i <= rows; i++)
20 | {
21 | for(j = 1; j <= columns; j++)
22 | {
23 | if(i == 1 || i == rows || j == 1 || j == columns)
24 | {
25 | cout << ch;
26 | }
27 | else
28 | {
29 | cout << " ";
30 | }
31 | }
32 | cout << "\n";
33 | }
34 | return 0;
35 | }
36 |
--------------------------------------------------------------------------------
/Triangles/Print a pyramid using numbers.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main() {
5 |
6 | int rows, count = 0, count1 = 0, k = 0;
7 |
8 | cout << "Enter number of rows: ";
9 | cin >> rows;
10 |
11 | for(int i = 1; i <= rows; ++i) {
12 | for(int space = 1; space <= rows-i; ++space) {
13 | cout << " ";
14 | ++count;
15 | }
16 |
17 | while(k != 2*i-1) {
18 | if (count <= rows-1) {
19 | cout << i+k << " ";
20 | ++count;
21 | }
22 | else {
23 | ++count1;
24 | cout << i+k-2*count1 << " ";
25 | }
26 | ++k;
27 | }
28 | count1 = count = k = 0;
29 |
30 | cout << endl;
31 | }
32 | return 0;
33 | }
34 |
--------------------------------------------------------------------------------
/A simple calculator/Calculator.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | using namespace std;
7 |
8 | int Fact(int a);
9 |
10 | int Power (int ,int);
11 |
12 | int main()
13 | {
14 | float a,b;
15 | char n,op;
16 | //n= nothing;
17 | n=='n';
18 | cout<<"______________________________"<>a;
21 | cout<<"Enter the operator : ";
22 | cin>>op;
23 | cout<<"Enter the second number : ";
24 | cin>>b;
25 |
26 | switch(op)
27 | {
28 | case '*':cout<