DIY C Program on AVERAGE SALE (http://www.bloggerspot.tk/)



AVERAGE SALE

 DIY C Program on AVERAGE SALE (http://www.bloggerspot.tk/)

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

Solution:

#include<stdio.h>
int main()
{
float a, b, c, d, e, f, g;
printf("Enter sale in first month\n");
scanf("%f", &a);
printf("Enter sale in second month\n");
scanf("%f", &b);
printf("Enter sale in third month\n");
scanf("%f", &c);
printf("Enter sale in fourth month\n");
scanf("%f", &d);
printf("Enter sale in fifth month\n");
scanf("%f", &e);
printf("Enter the average sales in 6 months\n");
scanf("%f", &f);
g = 6 * f - a - b - c - d - e;
printf("The sale in the sixth month is Rs.%0.2f\n", g);
return 0;
}

No comments:

Post a Comment

Your Comments here.

© Copyright 2015. Website by Way2themes - Published By Gooyaabi Templates