Skip to main content

C One Dimensional Array.

 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) 

     One_dimensional_array.c



Comments

Popular posts from this blog

Logical Reasoning.

  Quiz 2:- 2.In a code language QUEEN is written as OVCFL, then KING is written as a. IJLH b. MKOF c. PHIK d. FOKM Answer:-  a. IJLH Explanation: Alphabet Series - A B C D E F G H I J K L M N O P Q R S T U V W X Y Z The coding follows the rule -2, +1, -2, +1, etc. That means Q -2 = O U+1=V E-2=C, etc.

Logical Reasoning

Quiz 4:-   4. If DOOR = 25, LOWER=37, TOWER=18, then OVER = ? a.85 b.60 c.45 d.06 Answer:- d.06 Explanation:- Alphabets and their positions |A|B|C|D|E|F|G|H|I|J| | K|L|M|N|O|P|Q|R| |S|T |U|V|W|X|Y|Z| |1|2 |3|4 |5|6|7 |8|9|10| |11|12|13|14|15|16|17|18| |19|20|21|22|23|24|25|26 | Rule:- Add positions of alphabets and then reverse the result DOOR = 4+15+15+18 = 52 = reverse 52 to give 25 and so on...

Logical Reasoning

  Quiz 7 7. CEGI : JHFD :: KMOQ : ? a. LPNR b. RNPL c. LNPR d. RPNL Answer:  d. RPNL Explanation: Alphabet Series:- A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Write the next letters after the letters CEGI. We get DFHJ. Reverse them to get JHFD Next letters after KMOQ is LNPR. Reversing them we get RPNL