How To Declare An Array In C++
How To Declare An Array In C++
It is the collection of the record is called array.It has two types
1. Single dimensional array - []
2. Multi dimensional array - [] []
Single dimensional array - []
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10],i,sum=0,avg;
clrscr();
cout<<"Enter the ten numbers is :"<<endl;
for(i=1;i<=10;i++)
{
cin>>a[i];
}
for(i=1;1<=10;i++)
{
sum=sum+a[i];
}
avg=sum/10;
cout<<"The given total of ten number is:"<<sum<<endl;
cout<<"The given average of ten number is:"<<avg<<endl;
getch();
}
Multi dimensional array - [] []
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j;
clrscr();
cout<<"Enter the firt matrix:"<<endl;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter the second matrix is:"<<endl;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
cin>>b[i][j];
}
}
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
cout<<"\t"<<c[i][j];
}
cout<<"\n";
}
getch();
}
0 Comments