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;

    clrscr();

    printf("How many numbers? ");

    scanf("%d", &n);

    sum = 0.0;

    i = 0;

    do {

    scanf("%f", &x);

    sum += x;

    i++;

    }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);

    getch();

}

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



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), 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