Here are a few examples of the do-while loop.
#include<stdio.h>
int main(){
int i=1;
do{
printf("6 * %d = %d \n",i,i*6);
i++;
}while(i<=10);
return 0;
}
6 * 1 = 6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30
6 * 6 = 36
6 * 7 = 42
6 * 8 = 48
6 * 9 = 54
6 * 10 = 60
#include<stdio.h>
void main()
{
int n,i=1,f=1;
printf("\n Enter The Number:");
scanf("%d",&n);
//LOOP TO CALCULATE THE FACTORIAL OF A NUMBER
do
{
f=f*i;
i++;
}while(i<=n);
printf("\n The Factorial of %d is %d",n,f);
}
Enter The Number:5
The Factorial of 5 is 120
#include<stdio.h>
void main()
{
int num,reverse=0,rem;
printf("Enter a number: ");
scanf("%d",&num);
do{
rem=num%10;
reverse=reverse*10+rem;
num/=10;
}while(num!=0);
printf("Reverse number %d\n",reverse);
}
Enter a number: 12345
Reverse number 54321
In the above-given do-while loop examples, we could clearly see that it is an exit-controlled loop.
Note: also read about do-while loop in c & while loop examples in c
If you like my post please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…