Wednesday 9 March 2016

AVERAGE SALE


A grocer has a sale of Rs. s1, Rs. s2, Rs. s3, Rs. s4 and Rs. s5 for 5 consecutive months. How much sale must he have in the sixth month so that he gets an average sale of Rs. x?

Write a C program to compute the sale in the 6th month.

Input Format: 
Input consists of 5 integers and 1 float. The five integers correspond to s1, s2, s3, s4 and s5. The float input corresponds to x.

Output Format: 
Refer sample input and output for formatting specifications. The float values are displayed correct to 2 decimal places.

Sample Input and Output: 
[All text in bold corresponds to input and the rest corresponds to output]
Enter sale in first month
6435
Enter sale in second month
6927
Enter sale in third month
6855
Enter sale in fourth month
7230
Enter sale in fifth month
6562
Enter the average sales in 6 months
6500
The sale in the sixth month is Rs.4991.00

Code:
  #include<stdio.h>
int main(){
  float s[5],a;
  
  printf("Enter sale in first month\n");
  scanf("%f",&s[0]);
  printf("Enter sale in second month\n");
  scanf("%f",&s[1]);
  printf("Enter sale in third month\n");
  scanf("%f",&s[2]);
  printf("Enter sale in fourth month\n");
  scanf("%f",&s[3]);
  printf("Enter sale in fifth month\n");
  scanf("%f",&s[4]);
  printf("Enter the average sales in 6 months\n");
  scanf("%f",&a);
  printf("The sale in the sixth month is Rs.%.2f",(6*s[5])-(s[0]+s[1]+s[2]+s[3]+s[4]));
  
  
  return 0;
}

4 comments:

  1. please provide same program in java

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. (6*a)-(s[0]+s[1]+s[2]+s[3]+s[4]));

    ReplyDelete
  4. This blog provides good info for fresher student . This will help aspirants to move ahead on the desired path.

    6 Months Industrial Training Institute in Gurgaon | 6 Months Live Project Training in Gurgaon

    ReplyDelete