C Program to Accept and Display Array Elements

C Program to Accept and Display Array Elements:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



#include<stdio.h>
main()
{
   int i,arr[50],num;

   printf("Enter no of elements :");
   scanf("%d",&num);

   //Reading values in an Array
   printf("\nEnter %d elements: ",num);
   for(i=0;i<num;i++)
    {
      scanf("%d",&arr[i]);
    }

   //Printing all array elements
   printf("Array elements are\n");
   for(i=0;i<num;i++)
    {
      printf("%d\t",arr[i]);
    }
}

OUTPUT:

Enter no of elements :5

Enter 5 elements: 1 7 3 9 4
Array elements are
1       7       3       9       4

Leave a Reply

Your email address will not be published. Required fields are marked *

four × 1 =