Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Define a one-dimensional integer array, call a random number to generate 1 and 10 elements in the range of 100, and sum all even numbers and output the final result.
Define a one-dimensional integer array, call a random number to generate 1 and 10 elements in the range of 100, and sum all even numbers and output the final result.
As the name implies, you only need to calculate the sum result:

# include & ltstdlib.h & gt

# include & ltstdio.h & gt

# include & lttime.h & gt

int main()

{

int n= 10,i= 1,count = 0;

srand(time(0));

for(; I & ltn;; i++)

{

int m;

if((m = rand()% 100+ 1)& amp; 1)= = 0)/* x & amp; 1==0 means it is even */

{

count+= m;

}

}

printf("%d\n ",count);

getchar();

}