Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77e5a41

Browse files
Add .cpp file
1 parent 302569d commit 77e5a41

File tree

8 files changed

+147
-0
lines changed

8 files changed

+147
-0
lines changed

‎05)ifElse.cpp‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int age;
7+
cout << "Enter your age: ";
8+
cin >> age;
9+
10+
if (age > 150 || age < 1)
11+
{
12+
cout << "Invalid age";
13+
}
14+
15+
else if (age >= 18)
16+
{
17+
cout << "You can vote";
18+
}
19+
20+
else
21+
{
22+
cout << "You cannot vote";
23+
}
24+
25+
return 0;
26+
}

‎06)switchCase.cpp‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int age;
7+
cout << "Enter your age: ";
8+
cin >> age;
9+
10+
switch (age)
11+
{
12+
case 12:
13+
cout << "You are 12 years old" << endl;
14+
break;
15+
16+
case 18:
17+
cout << "You are 18 years old" << endl;
18+
break;
19+
20+
default:
21+
cout << "You are neither 12 nor 18 years old";
22+
}
23+
24+
return 0;
25+
}

‎07)whileLoop.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int index = 0;
7+
while (index < 34)
8+
{
9+
cout << "We are at index number " << index << endl;
10+
index = index + 1;
11+
}
12+
13+
return 0;
14+
}

‎08)doWhileLoop.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int index = 0;
7+
do
8+
{
9+
cout << "We are at index number " << index << endl;
10+
index = index + 1;
11+
} while (index < 33);
12+
13+
return 0;
14+
}

‎09)forLoop.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
for (int i = 1; i <= 34; i++)
7+
{
8+
cout << "The value of i is " << i << endl;
9+
}
10+
11+
return 0;
12+
}

‎10)function.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int add(int a, int b)
5+
{
6+
int c;
7+
c = a + b;
8+
return c;
9+
}
10+
11+
int main()
12+
{
13+
int num1 = 5, num2 = 4;
14+
int result = add(num1, num2);
15+
cout << result;
16+
17+
return 0;
18+
}

‎11)arrays.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int marks[5];
7+
8+
for (int i = 0; i < 5; i++)
9+
{
10+
cout << "Enter marks for " << i + 1 << " student is ";
11+
cin >> marks[i];
12+
}
13+
14+
for (int i = 0; i < 5; i++)
15+
{
16+
cout << "Marks of " << i + 1 << " student is " << marks[i] << endl;
17+
}
18+
19+
return 0;
20+
}

‎12)multiDimensionalArray.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int arr2d[2][3] = {{1, 2, 3},
7+
{4, 5, 6}};
8+
9+
for (int i = 0; i < 2; i++)
10+
{
11+
for (int j = 0; j < 3; j++)
12+
{
13+
cout << "The value at " << i << "," << j << " is " << arr2d[i][j] << endl;
14+
}
15+
}
16+
17+
return 0;
18+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /