Today Oz is playing with two lists and . List contains elements. List is formed by replacing every element of List by average value of all elements before current element including current one.
For example :
If list is like : then
list will be like :
Now you are given list and you have to find list . So help Oz with this task.
Input :
First line contain an integer - size of list
Second line contains space separated integers - elements of list
First line contain an integer - size of list
Second line contains space separated integers - elements of list
Output :
Output space separated integers - elements of list
Test data is such that list elements are always integers.
Constraints :
Implementation:
#include <stdio.h>
int main()
{
int *a,*b;
int n;
int i,average,current = 1, j=0,sum=0,res;
scanf("%d",&n);
a=(int*)malloc(sizeof(int)*n);
b=(int*)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
{
scanf("%d",(b+i));
res=(*(b+i)*current)-sum;
sum += res;
current++;
*(a+i) = res;
}
for(i=0;i<n;i++)
printf("%d ",*(a+i));
free(a);
free(b);
return 0;