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. The number of odd numbers and even numbers should be equal.
#include <stdio.h>
#include <conio.h>
void oddeven (int arr[], int l );
void main ( )
{
int arr[10], i;
clrscr ( );
for ( i = 0; i < 10; i++ )
{
printf("\n\t\t Enter a number..:"); scanf("%d",&arr[i]);
}
oddeven ( arr, 10 );
getch ( );
}
void oddeven ( int arr[], int l )
{
int i, brr[10], j = 0;
printf("\n\n\n\t\t The array is..:\n");
printf("\n\t POSITION:");
for ( i = 0; i < l; i++ )
{
printf("%d ",i);
}
printf("\n\t ELEMENTS:");
for ( i = 0; i < l; i++ )
{
printf("%d ",arr[i]);
}
for ( i = 0; i < l; i++ )
{
if ( arr[i] % 2 == 0 )
{
brr[j] = arr [i];
j = j + 2;
}
}
j = 1;
for ( i = 0; i < l; i++ )
{
if ( arr [i] % 2 != 0 )
{
brr[j]=arr[i];
j = j + 2;
}
}
for ( i = 0; i < l; i++ )
{
arr[i]=brr[i];
}
printf("\n\n\n\t\t The resultant array is..:\n");
printf("\n\t POSITION:");
for ( i = 0; i < l; i++ )
{
printf("%d ",i);
}
printf("\n\t ELEMENTS:");
for( i = 0; i < l; i++ )
{
printf("%d ",arr[i]);
}
}
Click here to contact us
#include <stdio.h>
#include <conio.h>
void oddeven (int arr[], int l );
void main ( )
{
int arr[10], i;
clrscr ( );
for ( i = 0; i < 10; i++ )
{
printf("\n\t\t Enter a number..:"); scanf("%d",&arr[i]);
}
oddeven ( arr, 10 );
getch ( );
}
void oddeven ( int arr[], int l )
{
int i, brr[10], j = 0;
printf("\n\n\n\t\t The array is..:\n");
printf("\n\t POSITION:");
for ( i = 0; i < l; i++ )
{
printf("%d ",i);
}
printf("\n\t ELEMENTS:");
for ( i = 0; i < l; i++ )
{
printf("%d ",arr[i]);
}
for ( i = 0; i < l; i++ )
{
if ( arr[i] % 2 == 0 )
{
brr[j] = arr [i];
j = j + 2;
}
}
j = 1;
for ( i = 0; i < l; i++ )
{
if ( arr [i] % 2 != 0 )
{
brr[j]=arr[i];
j = j + 2;
}
}
for ( i = 0; i < l; i++ )
{
arr[i]=brr[i];
}
printf("\n\n\n\t\t The resultant array is..:\n");
printf("\n\t POSITION:");
for ( i = 0; i < l; i++ )
{
printf("%d ",i);
}
printf("\n\t ELEMENTS:");
for( i = 0; i < l; i++ )
{
printf("%d ",arr[i]);
}
}
Click here to contact us
No comments:
Post a Comment