#include<conio.h>
#include<stdio.h>
void avgOfEvenNumbreInArray(int [], int);
void avgOfOddNumberInArray(int [], int);
void main()
{
clrscr();
int i, j, evenCount, oddCount, evenSum, oddSum, n;
char ch;
int b[10];
//iniitalize variable with 0
evenCount = 0;
oddCount = 0;
evenSum = 0;
oddSum = 0;
i = 0;
n = 0;
ch = ' ';
printf("Enter the no: ");
//check for two condition either user quit in between or array is full.
while(i < 10)
{
scanf("%d", &b[i]);
i++; //increment the value;
}
//i contain the total element in array, i < 20 in every case.
printf("\nEnter your choise: ");
printf("\nPress 1 Even number in array . : ");
printf("\nPress 2 Odd number in array . : ");
printf("\nPress 3 Average of even no. : ");
printf("\nPress 4 Average of Odd no. : ");
printf("\nChoice : ");
scanf("%d",&n);
switch( n )
{
case 1 :
printf("\n Even no. : ");
for(j = 0; j < i; j++)
{
if(b[j] % 2 == 0)
{
printf("\t%d", b[j]);
}
}
break;
case 2:
printf("\n Even no. : ");
for(j = 0; j < i; j++)
{
if(b[j] % 2 != 0)
{
printf("\t%d", b[j]);
}
}
break;
case 3:
avgOfEvenNumbreInArray(b, i);
break;
case 4:
avgOfOddNumberInArray(b, i);
break;
default:
printf("\nInvalid choice");
}
getch();
}
void avgOfEvenNumbreInArray(int a[], int length) {
int i, totalEven = 0;
int sum = 0;
int avg = 0;
for(i = 0; i < length; i++) {
if(a[i] % 2 == 0) {
sum += a[i];
totalEven ++;
}
}
printf("\n Sum of even number = %d", sum);
printf("\n Total even number in array = %d", totalEven);
printf("\n Avg = %d", (sum / totalEven));
}
void avgOfOddNumberInArray(int a[], int length) {
int i, totalOdd = 0;
int sum = 0;
int avg = 0;
for(i = 0; i < length; i++) {
if(a[i] % 2 == 0) {
sum += a[i];
totalOdd ++;
}
}
printf("\n Sum of odd number = %d", sum);
printf("\n Total odd number in array = %d", totalOdd);
printf("\n Avg = %d", (sum / totalOdd));
}
#include<stdio.h>
void avgOfEvenNumbreInArray(int [], int);
void avgOfOddNumberInArray(int [], int);
void main()
{
clrscr();
int i, j, evenCount, oddCount, evenSum, oddSum, n;
char ch;
int b[10];
//iniitalize variable with 0
evenCount = 0;
oddCount = 0;
evenSum = 0;
oddSum = 0;
i = 0;
n = 0;
ch = ' ';
printf("Enter the no: ");
//check for two condition either user quit in between or array is full.
while(i < 10)
{
scanf("%d", &b[i]);
i++; //increment the value;
}
//i contain the total element in array, i < 20 in every case.
printf("\nEnter your choise: ");
printf("\nPress 1 Even number in array . : ");
printf("\nPress 2 Odd number in array . : ");
printf("\nPress 3 Average of even no. : ");
printf("\nPress 4 Average of Odd no. : ");
printf("\nChoice : ");
scanf("%d",&n);
switch( n )
{
case 1 :
printf("\n Even no. : ");
for(j = 0; j < i; j++)
{
if(b[j] % 2 == 0)
{
printf("\t%d", b[j]);
}
}
break;
case 2:
printf("\n Even no. : ");
for(j = 0; j < i; j++)
{
if(b[j] % 2 != 0)
{
printf("\t%d", b[j]);
}
}
break;
case 3:
avgOfEvenNumbreInArray(b, i);
break;
case 4:
avgOfOddNumberInArray(b, i);
break;
default:
printf("\nInvalid choice");
}
getch();
}
void avgOfEvenNumbreInArray(int a[], int length) {
int i, totalEven = 0;
int sum = 0;
int avg = 0;
for(i = 0; i < length; i++) {
if(a[i] % 2 == 0) {
sum += a[i];
totalEven ++;
}
}
printf("\n Sum of even number = %d", sum);
printf("\n Total even number in array = %d", totalEven);
printf("\n Avg = %d", (sum / totalEven));
}
void avgOfOddNumberInArray(int a[], int length) {
int i, totalOdd = 0;
int sum = 0;
int avg = 0;
for(i = 0; i < length; i++) {
if(a[i] % 2 == 0) {
sum += a[i];
totalOdd ++;
}
}
printf("\n Sum of odd number = %d", sum);
printf("\n Total odd number in array = %d", totalOdd);
printf("\n Avg = %d", (sum / totalOdd));
}
No comments:
Post a Comment
Please write your doubts