F Program to Half the even numbers and double the odd numbers in an array | CodeTheta

Program to Half the even numbers and double the odd numbers in an array

April 17, 2014

This program will check if the given number is odd or even then if the given number will even then the output will be half and if the given number will be odd then the output will be double of given number.
For example:
Entered array is : 5, 7, 6
Result will be : 10 ,14, 3

/* http://native-code.blogspot.com */

#include<stdio.h>
#include<conio.h>
#define MAX 20
void input(int [], int);
void convert(int [], int [], int);
void display(int [], int);
void main()
{
int a[MAX], b[MAX], i, max;
printf("/* http://native-code.blogspot.com */ \n\n Enter the maximum range:\n");
scanf("%d", &max);
input(a, max);
convert(a, b, max);
printf("\nThe original array is: ");
display(b, max);
printf("\n\nAfter execution: ");
display(a, max);
getch();
}
void display(int a[], int max)
{
int i;
for(i=0; i<max; i++)
printf("%d ", a[i]);
}
void input(int a[], int max)
{
int i;
printf("\nEnter elements:\n");
for(i=0; i<max; i++)
scanf("%d", &a[i]);
}
void convert(int a[], int b[], int n)
{
int i,c;
for(i=0; i<n; i++)
{
b[i]=a[i];
c=a[i];
if(c%2==0)
a[i]=(c/2);
else
a[i]=(c*2);
}
}

/* http://native-code.blogspot.com */

Post a Comment