Giter Site home page Giter Site logo

cgreenp / nptel-introduction-to-programming-in-c-assignment-3-question-2 Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 17 KB

NPTEL Introduction to Programming in C Assignment 3 Question 2

License: GNU General Public License v3.0

C 100.00%
c introduction-to-programming-in-c nptel nptel-assignments nptel-solutions

nptel-introduction-to-programming-in-c-assignment-3-question-2's Introduction

NPTEL-Introduction-to-Programming-in-C-Assignment-3-Question-2

NPTEL Introduction to Programming in C Assignment 3 Question 2

Question 2

When you keep track of stock prices, or your weight during a diet programme, the daily prices or weights fluctuate a lot. One way to identify the general trend is to keep track of the average over the last 3 days, for example. This technique often smooths out the fluctuations, and makes the trend clearer. This technique is called "moving average".

In this question, you have to output the "moving average" of a sequence of non-negative numbers. The moving average is the sequence of averages of the last 3 entries. For the first 2 numbers, no average is output.

For example, if the sequence of numbers is

a1, a2, a3, a4, a5

and k=3, then the 3-moving average is

(a3+a2+a1)/3, (a4+a3+a2)/3, (a5+a4+a3)/3.

Input

The input is a sequence of non-negative floating point numbers, terminated by a -1. The -1 is not part of the sequence. There will be at least 3 numbers in the sequence.

Output

You have to output the moving average of the sequence. The output should be printed correct to one digit after the decimal.

Sample Input 1

70.8 70.9 71.2 70.7 70.2 -1

Sample Output 1

71.0 70.9 70.7

Sample Input 2

1 2 0 1 -1

Sample Output 2

1.0 1.0

nptel-introduction-to-programming-in-c-assignment-3-question-2's People

Contributors

cgreenp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.