Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

do...while loop C

// Program to add numbers until the user enters zero

#include <stdio.h>
int main() {
  double number, sum = 0;

  // the body of the loop is executed at least once
  do {
    printf("Enter a number: ");
    scanf("%lf", &number);
    sum += number;
  }
  while(number != 0.0);

  printf("Sum = %.2lf",sum);

  return 0;
}
 
PREVIOUS NEXT
Tagged: #loop #C
ADD COMMENT
Topic
Name
4+1 =