ARRAY EXAMPLE IN C PROGRAMMING LANGUAGE

This example describes how to use array in c language.
Syntax:
     Declaration: Datatype array_name [size];
     Initialization: array_name[size];

Example:
  1. #include <stdio.h>
  2. int main ()
  3. {
  4.    int n[ 10 ]; // n is an array of 10 integers 
  5.    int i,j;
  6.    for ( i = 0; i < 10; i++ )
  7.    {
  8.       n[ i ] = i + 100; // set element at location i to i + 100 
  9.    }     
  10.    for (j = 0; j < 10; j++ )
  11.    {
  12.       printf("Element[%d] = %d\n", j, n[j] );//Print each array element on console
  13.    } 
  14.    return 0;
  15. }

Description:
In this example we first simply declare an array for 10 elements, initialize it using for loop, and print all the elements on console.

Line 4: This line declares an array of 10 elements.  
Line 5: Declares variable
Line 6 to 9: Initializes array from 100 to 109 values,
Line 10 to 13 :Prints value of this array. Here " %d " is used because array is of datatype "int".
                       n[j] means j position of element in the list  formed in "n[]" array.

рдорд░рд╛рдареАрдд рд╡рд░реНрдгрди :
рд╣реНрдпрд╛ рдЙрдзрд░реНрдгрд╛рдд рдЖрдкрдг рд╕реЛрдкреНрдпрд╛ рдкрджреНрдзрддреАрдиреЗ рдЕрд░рд░реЗ рдордзреНрдпреЗ рдХрд┐рдВрдордд рдЯрд╛рдХрд▓реЗрд▓реА рдЖрд╣реЗ рд╡ рддреНрдпрд╛ рдХрд┐рдВрдордд рдХрдиреНрд╕реЛрд▓ рд╡рд░ рджрд╛рдЦрд╡рд▓реА рдЖрд╣реЗ .

рдУрд│ рек: рд╣реА рдУрд│ рдореБрд│реЗ рдореЗрдорд░реА рдордзреНрдпреЗ резреж рдЕрдВрдХрд╛рдВрдЪреА рдЬрд╛рдЧрд╛ рдмрдирддреЗ. рд╣реЗ рдЖрдзреА рд▓рд┐рд╣рд┐рди рдЖрд╡рд╢реНрдпрдХ рдЖрд╣реЗ .
рдУрд│ рел:  рд╣реНрдпрд╛рдд рд╡рд░рд┐рдПрдмреНрд▓ рд╕рд╛рдареА рдореЗрдорд░реА рдордзреНрдпреЗ рдЬрд╛рдЧрд╛ рддрдпрд╛рд░ рд╣реЛрддреЗ.
рдУрд│ рем рддреЗ реп; рдЕрд░реНрд░реЗ рдордзреНрдпреЗ резрежреж рддреЗ резрежреп рд╣реЗ рдЕрдВрдХ рдЯрд╛рдХрд▓реЗ рдЖрд╣реЗ.
рдУрд│ резреж рддреЗ резрей:  рд╕рдЧрд│реА рдЕрд░реНрд░реЗ рдордзреНрдпреЗ рдЬрдорд╛ рдХреЗрд▓реЗрд▓реА рдХрд┐рдВрдордд рдХрдиреНрд╕реЛрд▓рд╡рд░ рд▓рд┐рд╣рд┐рд▓реА рдЬрддреЗ.
   

Comments

Popular Posts