Computer Science, asked by sammy5711, 7 months ago

Write a c program to find moving average of a sequence of non negative numbers

Answers

Answered by Ketangupta4155
1

Answer:

#include<stdio.h>

int main(){

   int num;  //number of elements

   int i;

   int sequence[100];  //numeber if sequence

   int sum = 0.0;            //sum if the sequence

   float avg;          // the average

   printf("Enter the number of number in the sequence:\n");

   scanf("%d", &num);

   while (num < 0 || sequence[num] < 0) {

       printf("No positine numbers!\n");

   }

   printf("Enter the sequence:\n");

   for (i=0; i < num; i++) {

       scanf("%d", &sequence[i]);

       sum += sequence[i];

   }

   avg = (float) sum / num;

   printf("Average is %.2f\n", avg);

   return(0);

}

Explanation:

Similar questions