Average Weight

SemiColon
By -
1 minute read
0
8. Write a C program that accepts two item’s weight (floating points' values ) and
 number of purchase (floating points' values) and calculate the average value of
 the items. (float number – 2 decimal point). 

Sample input:

Weight - Item1: 15
No. of item1: 5
Weight - Item2: 25
No. of item2: 4 

Sample Output:

Average Value = 19.44


Solution:

#include<stdio.h>
int main()
    {
        double W_I1, N_I1, W_I2, N_I2, a, b, c, d ,avg;

        printf("Weight - Item1: ");
        scanf("%lf", &W_I1);
        printf("No. of item1: ");
        scanf("%lf", &N_I1);
        printf("Weight - Item2: ");
        scanf("%lf", &W_I2);
        printf("No. of item2: ");
        scanf("%lf", &N_I2);

        a=W_I1*N_I1;
        b=W_I2*N_I2;
        c=a+b;
        d=N_I1+N_I2;
        avg=c/d;

        printf("Average Value = %.2lf\n", avg);

        return 0;

    }

Tags:

Post a Comment

0Comments

Post a Comment (0)