by Dinesh Thakur Category: Control Structures

The program segment given below using a do ...while loop and then determines the average of the given numbers.

#include <stdio.h>

void main()


    int n,i;

    float sum,x,avg;


    printf("How many numbers? ");

    scanf("%d", &n);

    sum = 0.0;

    i = 0;

    do {

    scanf("%f", &x);

    sum += x;


    }while (i < n);

    avg = sum/ n; /* sum is assumed to be of type float */

    printf ("The Sum is = %f \n",sum);

    printf ("The Average is = %f \n",avg);



    C Program Determine sum and average of several numbers entered from the keyboard.

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles