In this programme you will store the multiple values in the array and and display it. this is very simple after you giving the header and main files you take an array of 5 elements. or for understanding you assume you take the 5 boxes and assign values in it. like you have 5 boxes in the kitchen for sugar,salt etc. and you fill these boxes when you have some salt,sugar etc.
In the same way you array's element is boxes and the values you place in it like numbers, constants or any other which you wana place in it.
this is the basic example of array in our daily life.Array is very helpful for long fuctions it reduced the size of c++ code and you save alot of space and time.
WRITE PROGRAMME THAT DISPLAYS AN ARRAY
In this type of programme you take an array of any elements and after assigning the values in it using the for loop for displaying the element of an array. for loop is initialize from zero to any elements which you take in the array. if you assign more elements in the array your compiler give an error and the values can not be executed. after the for loop you simple place the variable which you take for for loop into the console output or cout. you will show all values you give to the compiler.CODE for C++
#include<iostream.h>
void main()
{
int a[5];// Take an array of 5 elements.
a[0]=0;// store values in it
a[1]=1;
a[2]=2;
a[3]=3;
a[4]=4;
for(int x=0;x<=4;x++)//using for loop
cout<<a[x]<<endl;// placing variable for display
}
OUTPUT
WRITE A PROGRAMME THAT DISPLAYS ARRAY IN REVERSE ORDER
In this programme all the programme is same as above but you make a little change in the for loop that you intialize the loop in reverse order see this code for understandingCODE for C++
#include<iostream.h>
void main()
{
int a[5];
a[0]=0;
a[1]=1;
a[2]=2;
a[3]=3;
a[4]=4;
for(int x=4;x>=0;x--)
cout<<a[x]<<endl;
}
OUTPUT
WRITE A PROGRAMME THAT DISPLAYS EVEN INDEXED ELEMENTS OF ARRAY
In this code you again make some change the logic of for loop see code
CODE for C++
#include<iostream.h>
OUTPUT
WRITE A PROGRAMME THAT DISPLYS ODD INDEXED NYMBERS OF ARRAY
In this code you again make some change the logic of for loop see code
CODE for C++
#include<iostream.h>
OUTPUT
thank you for reading my article
0 comments:
Post a Comment