Programming Tutorials

C Program to Find the Sum and Average of Numbers Using Do-While Loop

Pinterest LinkedIn Tumblr
C Program to Find the Sum and Average of Numbers Using Do-While Loop
In this program we will find the sum and average of the given numbers using do-while loop which allows to calculate the sum and average.
Do-while loop is a looping condition where statements are executed continuously until the condition validates and test the condition after having executed the statements within the loop.
This means that do-while would execute its statements at least once, even if the condition fails for the first time.
Scanf() command is used here to allow enter the numbers and sum=sum+num; to sum the numbers within do-while loop.

C Program to Find the Sum and Average of Numbers Using Do-While Loop


  1. Declare two integers i and n and also initialize i with 0.
  2. Declare three floats sum, avg and num and initialize sum with 0.
  3. Print the message on the screen to enter how many numbers want to find sum.
  4. Use do-while loop to insert the numbers calculate the sum and average.



void main()

 int i=0,n;
 float sum, avg, num;



 printf("How many numbers you want to find sum and averagen");

 printf("Enter the numbersn");

  scanf("%f", &num);

 while (i<n);


 printf("Sum=%fn", sum);
 printf("Average=%fn", avg);

Read Next: Write a Program in C to Find if a Number is Present in a List or not


Shuseel Baral is a web programmer and the founder of InfoTechSite has over 8 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.


  1. J.A.A.M.Jayasooriya

    Hello all,
    I have a question..
    Actually I want to get average for n numbers.My condition is if typing the numbers I want to end that I type some character like as q,
    after that calculate the average.

  2. thanks.. i really appreciate.. it solved my assignment