Do while loop Statement

Do while loop Statement

In do..while loop control statement, while loop is executed irrespective of the condition for first time. Then 2nd time onwards, loop is executed until condition becomes false.

do while

 

Example

#include <stdio.h>

int main()

{ int p=1;

do

{

printf(“Value of p is %d\n”,p);

p++;

}

while(p<=4 && p>=2);

return 0;

}

Output
Value of i is 1

Value of i is 2

Value of i is 3

Value of i is 4

WAP to add numbers until user enters zero

#include<stdio.h>

void main()

{

double number1, s1 = 0;

do

{

printf(“Enter the number here: “);

scanf(“%lf”, &number1);

s1 += number1;

}

while(number1 != 0.0);

printf(“Sum = %.2lf”,s1);

}

Output

Enter the number here: 1.5

Enter the number here: 2.4

Enter the number here: -3.4

Enter the number here: 4.2

Enter the number here: 0

Sum = 4.70

 

Leave a Reply

Your email address will not be published. Required fields are marked *