by Dinesh Thakur Category: Array Pointer and Union

Arrays are declared as follows:

 

int p[5];

float temp[30];

char a[7];

 

The quantity mentioned inside the parenthesis denotes the subscript and it takes non-negative values. p[5] denotes that the range for the subscripts is 0..4 and that the array elements are p[0] .... p[4]. The first declaration int informs the compiler that the elements of the array named p can take only integer values and the second and third declarations inform the compiler that the elements of the array temp can take float values and the elements of the array a can take character values.

 

Following are some examples to illustrate the use of one-dimensional arrays.

 

Example

 

The program inputs the salary of 10 employees and finds the enhanced salary of employees with 15% raise in their salaries.

 

 

#include<iostream.h>
#include<conio.h>
void main()
{
            float emp_sal[10],newemp_sal[10];
            clrscr();
            cout<<"Enter 10 Numbers : ";
            for(int i=0;i<10;i++)
            {
                            cin>>emp_sal[i];
            }
               for(i=0;i<10;i++)
           {
                  newemp_sal[i] = ( emp_sal[i] *1.15);
                  cout << newemp_sal[i]<<"  " ;
           }
                     getch();
}

One Dimensional Arrays



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles