/* write a program that randomly generates 10 integers in range (min, max) (min and max are user input). The program finds the product of sqrt's values for all non-negative random ints, and finds the average of all negative random ints */ #include #include #include #include int main(){ int i,min, max, num, sum_neg=0, count_neg=0; double product=1.0, result; srand(time(NULL)); printf("enter min and max range for random numbers\n"); scanf("%d%d",&min,&max); for(i=0;i<10;i++){ num=rand()%(max-min+1)+min; //example: min=5, max=10 5+rand()%(10-5+1)=5+rand()%6 //rand()%6 generates numbers between 0 and 5, 0+5=5, 5+5 = 10 if(num>=0){ result=sqrt(num); product*=result; printf("The sqrt of %d is %f\n",num,result); } else{ printf("%d is negative\n",num); sum_neg+=num; count_neg++; } } printf("\nproduct of non-negative sqrt's is %f\n",product); if(count_neg>0) printf("average of negatives is %f\n", (double)(sum_neg)/count_neg); else printf("no negatives\n"); return 0; }