Tuesday, 24 February 2015

Arrays in C++

Single dimensional array:

#include<iostream.h>
#include<conio.h>
void main()
{
int n[5]={25,35,45,55,65};
int i;
clrscr();
for(i=0;i<5;i++)
cout<<”num “<<i+1<<n[i]<<endl;
getch();
}

Double dimensional array:

#include<iostream.h>
#include<conio.h>
void main()
{
int n[5][5];
int row,col;
clrscr();
for(row=0;row<5;row++)
{
for(col=0;col<5;col++)
{
cout<<”Enter the value of row[“ <<row+1 <<]”col[“ <<col+1<<”]”;
cin>>n[row][col];
}
}
cout<<”The given array values are”<<endl;
for(row=0;row<5;row++)
for(col=0;col<5;col++)
cout<<”The given array values are[“ <<row+1 <<]”col[“ <<col+1<<”]”<<n[row][col]<<endl;
getch();

}

No comments:

Post a Comment