Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int n;
- printf("Enter the number of values\n");
- scanf("%d",&n);
- printf("Enter the %d years one by one \n",n);
- int year[n];
- for(int i=0 ; i<n ; i++){
- scanf("%d",&year[i]);
- }
- printf("Enter the sales for each year one by one \n");
- int sale[n];
- for(int i=0 ; i<n ; i++){
- scanf("%d",&sale[i]);
- }
- float forcast[n+1];
- forcast[0] = forcast[1] =forcast[2] = 0;
- for(int i=3 ; i<=n ; i++ ){
- forcast[i] = (float) (sale[i-1] + sale[i-2] + sale[i-3] )/3;
- }
- printf("\n|Year\tNOS\tForcasting|\n");
- for(int i=0 ; i<n ; i++){
- printf("|%d | \t %d | \t %.2f\n",year[i],sale[i],forcast[i]);
- }
- printf("|%d | \t NA | \t %.2f",year[n-1]+1,forcast[n]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement