explain the use of break and continue statement with tge help of a program
Answers
Answered by
1
Answer:
// Program to calculate the sum of a maximum of 10 numbers
// If a negative number is entered, the loop terminates
# include <stdio.h>
int main()
{
int i;
double number, sum = 0.0;
for(i=1; i <= 10; ++i)
{
printf("Enter a n%d: ",i);
scanf("%lf",&number);
// If the user enters a negative number, the loop ends
if(number < 0.0)
{
break;
}
sum += number; // sum = sum + number;
}
printf("Sum = %.2lf",sum);
return 0;
}
Explanation:
Similar questions
Chinese,
5 months ago
English,
5 months ago
Math,
5 months ago
Math,
10 months ago
Computer Science,
1 year ago