-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path4_control_flows.cpp
More file actions
82 lines (71 loc) · 1.49 KB
/
4_control_flows.cpp
File metadata and controls
82 lines (71 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
// There are following data types inside the c++
char a='M';
string h="Mayur";
bool b=0;
// for the integers we have three choices based on the memory
short c=0;
int d=42798;
long e=1234567891011;
// float , decimal point type of the variables we have two choices
float f=3.14;
double g=3.141591254678;
cout<<a<<"\n"<<h<<"\n"<<b<<"\n"<<c<<"\n"<<d<<"\n"<<e<<"\n"<<f<<"\n"<<g<<endl;
// control flows - If else if else
if (c<d)
{
cout<<e<<endl;
}
else if (c>d)
{
cout << a << endl;
}
else
{
cout << b << endl;
}
// switch case
switch(3)
{
case 1:
{
cout <<"A"<< endl;
}
case 2:
{
cout << "B"<<endl;
}
default:
{
cout << "Z"<<endl;
}
}
// for loop (initialization, condition, increment)
int array[]={1,2,3,4,5};
for (int i=0;i<=4;i++)
{
cout <<array[i]<<endl;
}
// vector and for loop
vector<int> vector1={10,11,12,13,14};
vector<int>::iterator it;
for (auto it:vector1)
{
cout<<it<<endl;
}
// while loop
int i=0;
while(i<5)
{
cout <<"True"<<endl;
i++;
}
// we could also use the do while loop to increment before checking the condition
return 0;
}