C One Dimensional Array
What is One Dimensional Array ?
An Array which has only one subscript is known as One Dimensional Array.
i.e. int arr[10].
Syntax :-
Data_type Variable_name[Size];
Rules For Declaring One Dimensional Array :
1: An Array variable must be declared before being used in Program.
2: The declaration must have a datatype (int , float , char , double , etc..), variable name , subscript.
3: The subscript represents the size of the Array. if the size if 5 , we can store 5 elements.
4: An Array index always starts from 0.
If an array variable is declared as arr[15] , then it range from 0 to 14.
5: Each array elements stored in separate memory location.
In C-language an Array variable is also initialize without mentioning the size of an Array.
Declaration :-
1 : int Salary[5] = { 10000 , 12000 , 12300 , 20000 , 21000 };
2 : int Salary[] = { 10000 , 12000 , 12300 , 20000 , 21000 };
PROGRAM :-
#include<stdio.h>
void main()
{
int Salary[5];
int i,n=5;
//Input the Salaries
printf("Enter 5 Salaries\n");
for(i=0;i<n;i++){
scanf("%d",&Salary[i]);
}
// printing the All salaries
printf("\n<---Salaries--->\n");
for(i=0;i<n;i++){
printf(" Salary %d = %d\n", i+1, Salary[i]);
}
}
OUTPUT :-
Enter 5 Salaries
10000
12000
12300
20000
21000
<- - - Salaries - - ->
Salary 1 = 10000
Salary 2 = 12000
Salary 3 = 12300
Salary 4 = 20000
Salary 5 = 21000
Program File:(click the following .c file to get the program file)
Comments
Post a Comment