Ticker

6/recent/ticker-posts

Arrays in Data Structure

 ARRAY

What is an Array ??

An array can be defined as number of memory Locations, each of which can be store the same data type and which can be refrences through the same variable name.

How to create an array ?

1. Declaration of Array 

#include<iostream>

using namespace std;0

main()

{

int a[10];

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

cout<<a[i]<<",";

}

// it will give us garbage value
 
2. initialise of Array 

 #include<iostream>

using namespace std;

main()

{

int a[10]={1,2,3,4,5,6,7,8,9,10};

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

cout<<a[i]<<",";
}

3. You want to input element in array

#include<iostream>
using namespace std;
main()
{
int a[10];
{
for(int i=0;i<=9;i++)
cin>>a[i];
}
for(int i=0;i<=9;i++)
cout<<a[i]<<",";
}

4. update into squre

#include<iostream>
using namespace std;
main()
{
int a[10];
{
for(int i=0;i<=9;i++)
cin>>a[i];
}
{
for(int i=0;i<=9;i++)
a[i]=a[i]*a[i];
}
for(int i=0;i<=9;i++)
cout<<a[i]<<",";
}


Post a Comment

0 Comments