HP C A.06.05 Reference Manual
Statements
do…while
Chapter 6160
{
int num, sum, square_sum;
char answer;
printf("\n");
do
{
printf("Enter an integer: ");
scanf("%d", &num);
sum = (num*(num+1))/2;
square_sum = (num*(num+1)*(2*num+1))/6;
printf("The summation of %d is: %d\n", num, sum);
printf("The summation of its squares is: %d\n",
square_sum);
printf("\nAgain? ");
fflush(stdin);
scanf("%c", &answer);
} while ((answer != 'n') && (answer != 'N'));
}
If you execute this program, you get the following output:
Enter an integer: 10
The summation of 10 is: 55
The summation of its squares is: 385
Again? y
Enter an integer: 25
The summation of 25 is: 325
The summation of its squares is: 5525
Again? n