C++ program for Basic understanding of arrays.

a) How to input array and print a specific index's value.

#include<iostream>
using namespace std;
void main()
{
char n[10];
for (int i=0;i<10;i++)
{
       cin>>n[i];
      
}
cout<<n[5];
cout<<endl;
system("pause");

}

 


Output:

b) How to input at a specific index

#include<iostream>
using namespace std;
void main()
{
float arr[7];
cout<<"enter the value of 5 index"<<endl;
cin>>arr[4];
cout<<"The value of 5 index"<<arr[4]<<endl;
system("pause");
}

Output:


c) How to set default value to whole array.


#include<iostream>
using namespace std;
void main()
{
int g[5];
for(int i=1;i<5;i++)
{
       g[i]=8;
       cout<<"Array = "<<g[i]<<endl;
}

Comments