Write a program to input the price of n products in arrays and find total and avg price.

CODE




Write a program to input the price of n products in arrays and find total and avg price.

int main()
{
    int i;
    float n,total=0,avg,a[10];
    printf("\n enter the number of products(less than 10):");
    scanf("%f",&n);
    for(i=0;i<n;i++)
    {
        printf("\n enter the price of %d product:",i+1);
        scanf("%f",&a[i]);
        total+=a[i];
    }
    avg=total/n;
    printf("\n Total price=%f \n Average price=%f",total,avg);
}


Output:
enter the number of products(less than 10): 4

 enter the price of 1 product:234
 enter the price of 2 product:543
 enter the price of 3 product:754
 enter the price of 4 product:234

 Total price=1765.000000
 Average price=441.250000

Write a program to input the price of n products in arrays and find total and avg price. Write a program to input the price of n products in arrays and find total and avg price. Reviewed by Unknown on December 16, 2018 Rating: 5

No comments:

If you have any doubt or query ,comment below:

Programming copyright © 2018-19. Powered by Blogger.