C program to print alternate elements from an array

Alternate elements

This program illustrate the concept to print a alternate elements from an array.Array stores the element in contiguous memory location.Users can input only one data type of elements in the array at one time.

  • We have first defined the size of array i.e. “x[100]”.
  • After getting the size of array users will enter the elements in array
  • Once user will enter all the elements.Program will give output using logic “i=i+2”.
#include<stdio.h>
#include<conio.h>
void main()
{
 int x[100],i,y;
 clrscr();
 printf("Enter size of array:- ");
 scanf("%d",&y);
 printf("Enter elements in array:- ");
 for(i=0;i<y;i++)
  {
   scanf("%d",&x[i]);
  }
printf("Alternate elements in array :- ");
for(i=0;i<y;i=i+2)
 {
  printf("\n%d",x[i]);
 }
getch();
}

OUTPUT:-

Alternate elements


Inserting element into sorted array

Inserting element into sorted array

Leave a Reply

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