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

Lecture 4

Uploaded by

abirkabir23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lecture 4

Uploaded by

abirkabir23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Introduction To

Programming
Content
• Arrays
Arrays

• Arrays is a set of ordered data items.


• Arrays are used to store multiple values in a single variable, instead of
declaring separate variables for each value.
• To declare an array, define the variable type, specify the name of the
array followed by square brackets and specify the number of
elements it should store.
• Syntax-
Datatype array_name [array size];
Arrays...
Example--
• string courses[3];
• string courses[3] = {"C++", "Java", "C#"};
• int number[4] = {10, 20, 30,40};
string courses[] = {"C++", "Java", "Python"};
cout<< courses[0]<<"\n";
cout<< courses[1]<<"\n";
cout<< courses[2]<<"\n";
Arrays...
int main() int main() {
{ int number[4] = {11,12,13,14};
string courses[3] = {"C++", "Java", "C#"}; number[3]={30};
cout << courses[0]; cout << number[3];
return 0; return 0;
} }
int main() string courses[4] = {"C++", "Java", "C#",
{ "Python"};
int number[4] = {11,12,13,14}; for (int i = 0; i < 4; i++)
cout << number[3]; {
return 0; cout << courses[i] << "\n";
} }
Arrays...
string courses[4] = {"C++", "Java", "C#", "Python"};
courses[3] = {"C"};
for (int i = 0; i < 4; i++) string courses[3] ;
{ cin>> courses[0];
cout << courses[i] << ", "; cin>> courses[1];
} cin>> courses[2];

for(int i=0; i<3; i++)


string courses[3] = {"C++", "Java", "C#"}; {
for (int i = 0; i < 3; i++) cout<< "Course Name:
{ "<<courses[i]<<"\n";
cout << i << " No Index: " << courses[i] << "\n"; }
}
Arrays...
int main() {
string courses[10] ; int main()
{
for (int i=0; i<10; i++) int num[4] = {12,15,20,18};
{ for(int i=0;i<=3;i++)
cout<< "Enter Course Name: "<< i <<" "; {
cin>> courses[i]; if(i==3)
} {
num[i]= {17};
for(int i=0; i<10; i++) }
{ cout << "Marks is: "<<num[i]<<"\n";
cout<< "Course Name: "<<courses[i]<<"\n"; }
} return 0;
}
return 0;
}

You might also like