Tuesday, March 22, 2011

Program for Application of Arrays in Data Structure with Example

//Implementation of a Static Contiguous List

Program

#include<stdio.h>

#include<conio.h>
void main()
{
   void read(int *,int);
   void dis(int *,int);
   int a[5],i,sum=0;

   clrscr();
   printf("Enter the elements of array \n");
   read(a,5);      /*read the array*/
   printf("The array elements are \n");
   dis(a,5);
}

void read(int c[],int i)
{
   int j;
   for(j=0;j<i;j++)
   scanf("%d",&c[j]);
   fflush(stdin);
}

void dis(int d[],int i)
{
   int j;
   for(j=0;j<i;j++)
      printf("%d ",d[j]);
   printf("\n");
}

Example

Input
Enter the elements of the first array
15
30
45
60
75
Output
The elements of the first array are
15 30 45 60 75

No comments:

Post a Comment