About Me

My photo
santrampur, gujarat, India
i am a hunger of knowledge

Monday, December 27, 2010

arrays

ARRAY -             
                                    Array is a list or collection of data items which are stored in the form of a table, referred to by a common variable name is called “array Name” or “subscript variable name”.

                        ADVANTAGE OF USING AN ARRAY

§         Multi huge Quantity of data items can be stored under single variable name. 
§         Arrays save the memory space. 
§         Arrays help to arrange the data items in particular order. 
§         Data items searching are faster.

                        CONCEPT OF AN ARRAY
                                     Concept of an array can be classified into two types that are. 
A.     Single dimensional array. 
B.     Double/ multi dimensional array of matrix 

A.     Single dimensional array. 
Data items are stored in one single column with specified subscript variable name by using subscript range.


B.    Double / multi dimensional array of matrix.

In double dimensional array values are referred with respect to specified row column sing subscript variable name.



Above example indicates the 4/5 matrix all cell values are referred by the subscript name, quantity with respect to row and column.

                        PROGRAM:
/ * storing 10 sale’s amount in an array and find out total sale & best sale amount * /
                                         
            # include<iostream.h>
# include<conio.h>
Main ()
{
      Const int n=10;
      int sale_amt[100]; tot_amt; best=0;
      Clrscr ();

      / * storing values in an array * /
     
      For (i=0; i<=n; i++)
          {
                  printf (“Enter sales amount: \n”);
                  scanf (“%d”,&sale_amt[i]); 
   
/ * calculate the total sales find out best amount * /
tot_amt=tot_amt + sale_amt[i];
Best=sale_amt[i];
    }
/ * printing total and best sale amount* /
printf (“\n total sale amount =%d”, tot_amt);
      scanf (“\n best sale amount = %d”, best); 
}

No comments:

Post a Comment