Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <stdlib.h>
- #include <stdio.h>
- int main(int argc, char const *argv[]) {
- int n=0,A = -100,B = -A;
- int p_count,n_count;
- int p_sum,n_sum;
- float p_avr,p_avr
- srand(time (NULL));
- /* giving the seed from our system
- time to the rangom generator */
- printf("Input the size of array:\n>>");
- scanf("%d",&n);
- int arr[n];
- /* dont forget to scan array size
- before initializing the actual array */
- printf("\tarray arr[n] with n of %d:\t\n",n);
- for(int i=0; i<n; i++){
- // filling array with random numbers
- // the range of numbers from generator is [A;B]
- arr[i] = A +rand()%(B-A+1);
- printf("arr[%d]=%d\n",i,arr[i]);
- }
- // going array to find positive or negative numbers
- for(int i=0; i<n; i++){
- if(arr[i]>=0){
- p_count++;
- p_sum+=arr[i];
- }
- else{
- n_count++;
- n_sum+=arr[i];
- }
- }
- // calculating the average by definition
- p_avr = p_sum/p_count;
- n_avr = n_sum/n_count;
- printf("The average number is:\n for positive - %f\n for negative - %f\n",p_arv,n_avr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement