Friday 11 July 2014

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


C Program to Find the Sum and Average of Numbers Using Do-While Loop
In this program sum and average of of the given numbers are calculated using do-while loop.

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



Steps: 
  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.




Code:




#include<stdio.h>
#include<conio.h>



void main()
{

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

clrscr();

sum=0;

printf("How many numbers you want to find sum and average\n");
scanf("%d",&n);

printf("Enter the numbers\n");

do{
scanf("%f", &num);
sum=sum+num;
i++;
}

while (i<n);

avg=sum/n;

printf("Sum=%f\n", sum);
printf("Average=%f\n", avg);
getch();
}




Related Posts:


No comments:

Post a Comment

Powered by Blogger.

مساحات للبيع

اعلان

معلومات عنا

إعلانات

إجمالي مرات مشاهدة الصفحة

Search This Blog

اخبار عالمية

مقالات

أخبار

أخر المعلقين

فيديوهات

سلايدر

Tags

Contact us

متتبعون المدونة

Categories

Advertisement

40% Off

Translate

صور متنوعة

Facebook

Facebook users

Recent in Mens

FlatBook

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum rhoncus vehicula tortor, vel cursus elit. Donec nec nisl felis. Pellentesque ultrices sem sit amet eros interdum, id elementum nisi ermentum.Vestibulum rhoncus vehicula tortor, vel cursus elit. Donec nec nisl felis. Pellentesque ultrices sem sit amet eros interdum, id elementum nisi fermentum.




Comments

Contact Us

Name

Email *

Message *