Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Define an integer array with 20 elements, and find the average values of the elements with odd subscripts and even subscripts respectively. Answer in c language
Define an integer array with 20 elements, and find the average values of the elements with odd subscripts and even subscripts respectively. Answer in c language
# include & ltstdio.h & gtmain(){

int n[20]={ 1,2,3,4,5,6,7,8,9, 10, 1 12, 13, 14, 15, 16, 17, 18, 18

float v 1,v2;

int i,n 1,N2;

v 1 = v2 = n 1 = N2 = 0;

for(I = 0; I & lt20; i++)

{

if(i%2==0)v 1+=n[i],n 1++;

else v2+=n[i],n2++;

}

v 1/= n 1;

v2/= N2;

Printf ("average value of even subscript elements: %lf, average value of odd subscript elements: %lf\n", v 1, v2);

getch();

}