Wednesday 12 August 2015

C Program to read and print array of elements


Program:

#include< stdio.h >
#include< conio.h >
void main( )
{
          int a[5], i;
          for( i = 0; i < 5; i++ )
         {
                  printf("\nEnter the value for a[%d]: ", i);
                  scanf("%d", &a[i]);
         }
         printf("\nThe array elements are: \n");
         for( i = 0; i < 5; i++ )
         {
                 printf("%d\t", a[i]);
         }
}

Output:

Enter the value for a[ 1 ]: 3

Enter the value for a[ 2 ]: 2

Enter the value for a[ 3 ]: 1

Enter the value for a[ 4 ]: 9

Enter the value for a[ 5 ]: 7

The array elements are:

3 2 1 9 7



0 comments:

Post a Comment