Wednesday, 17 January 2018

Even Odd group print array

Q : Write a program using function to read an array from the user and print the odd number at odd position and prints the even numbers at even positions. For example input array is 1 2 3 4 and
output is 2 1 4 3.


Solution : 


/*==============================
     Girfa Student Help
     Program : Even Odd group print array
     More Program :http://girfahelp.blogspot.in/p/one-dimentaional-array-programming.html
================================*/
#include<stdio.h>
#include<conio.h>
#define MAX 5
void print(int*);
void main()
{
     int ar[MAX],i;

     clrscr();
     for(i=0;i<MAX;i++)
     {
          printf("Enter %d position number>> ",i+1);
          scanf("%d",&ar[i]);
     }
     print(ar);
     getch();
}
void print(int *p)
{
     int i,*a;
     printf("\nEven Position Number\n");
     for(i=0,a=p;i<MAX;i++)
     {
          if(*a%2==0)
              printf("%d,",*a);
          a++;
     }
     printf("\n\nODD Position Number\n");
     for(i=0,a=p;i<MAX;i++)
     {
          if(*a%2==1)
              printf("%d,",*a);
          a++;
     }

}


No comments:

Post a Comment