0% found this document useful (0 votes)
2 views3 pages

Do/While Loop in C Programming

The do/while loop is a control structure that executes a code block at least once before checking a condition, repeating as long as the condition remains true. Examples in C demonstrate its use for printing a multiplication table and summing user-entered numbers until zero is input. The document includes code snippets illustrating these functionalities.

Uploaded by

Ashfaq Khan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Do/While Loop in C Programming

The do/while loop is a control structure that executes a code block at least once before checking a condition, repeating as long as the condition remains true. Examples in C demonstrate its use for printing a multiplication table and summing user-entered numbers until zero is input. The document includes code snippets illustrating these functionalities.

Uploaded by

Ashfaq Khan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

The Do/While Loop

The do/while loop is a variant of the while loop. This loop will execute the code


block once, before checking if the condition is true, then it will repeat the
loop as long as the condition is true.

The example below uses a do/while loop. The loop will always be executed
at least once, even if the condition is false, because the code block is
executed before the condition is tested:
#include <stdio.h>

int main()

int i = 0;

do {

printf("%d\n", i);

i++;

while (i < 5);

return 0;

//Write a program in c to print table

1. #include<stdio.h>  
2. int main(){    
3. int i=1,number=0;    
4. printf("Enter a number: ");    
5. scanf("%d",&number);    
6. do{    
7. printf("%d \n",(number*i));    
8. i++;    
9. }while(i<=10);    
10. return 0;  
11. }   

// 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;
}
#include<stdio.h>

int main()

int num, sum = 0;

while(num!=0)

printf(“Enter a number:”);

scanf(“%d”, &num);

sum = sum + num;

printf(“sum = %d”, sum);

getch();

You might also like