Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Arrays in C Programming

August 25, 2013 Posted by: GPA Views: 530 0 comments

Problem

Arrays in C Programming. Write simple application using array.

Solution

An array is a collection of data of the same name and the same type. We can use it to store Integer, Boolean, Char types.

We can declare array with the following syntax:

int a[100]; - It is mean that we tell the computer to reserve 100 elements for type integer array a.

char c[100]; - It is mean that we tell the computer to reserve 100 elements for type char array a.

 

Example:

   

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
   //initialize array of 10 ellemnts
   int a[10]={10,45,8,9,7,6,4,2,3,5};
   int i;
   //print all elements in array
   printf("Element\tValue\n");
   for(i=0;i<10;i++){
       printf("%d\t%d\n",i,a[i]);
   }
   //we can decalre array in such way
   //If the array size is omitted from a definition with an initializer list, the number of elements
   //in the array will be the number of elements in the initializer list.
   int b[]={1,4,8,6,1,6,9,2,3,6};
   printf("\nElement\tValue\n");
   for(i=0;i<10;i++){
       printf("%d\t%d\n",i,b[i]);
   }
   //we can decalre array in such way
   int c[5];
   c[0]=5;
   c[1]=1;
   c[2]=2;
   c[3]=3;
   c[4]=4;
   printf("\nElement\tValue\n");
   for(i=0;i<5;i++){
      printf("%d\t%d\n",i,c[i]);
   }
   system("PAUSE");
   return 0;
}

Output

Arrays in C

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe