While Loop - { sum+=num; count++; printf("Enter a...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//This program finds the sum+avg until user enters -999 using the while loop //while loop: indeterministic: #of times to do loop is not known //entrance-controlled: condition to do loop is at top //flag -999 signals to end loop #include <stdio.h> void main() { int num,sum=0,count=0; float avg; printf("Enter a number, -999 to quit "); scanf("%d",&num); while(num!=-999)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { sum+=num; count++; printf("Enter a number, -999 to quit "); scanf("%d",&num); } //avg=sum/(float)count; //division by 0 if user enters -999 first //printf("The sum is %d\nThe average is %f\n",sum,avg); if(count!=0) { avg=sum/(float)count; printf("The sum is %d\nThe average is %f\n",sum,avg); } else printf("No data entered\n"); }...
View Full Document

This note was uploaded on 10/05/2011 for the course CS 36 taught by Professor Sethhochwald during the Spring '09 term at Irvine Valley College.

Ask a homework question - tutors are online