Table of Contents
In this tutorial, we will discuss the concept of C programming Language Do-while loop
In this post, we are going to learn how to use the do-while loop in C language
Do-while loop
What is the usage of the do-while loop in C? you can understanding after reading this article .
generally in programming languages, looping statements used in programming language to executes of block of code until the perticular condition is satisfied.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=1;
do{
printf(“%i”,i);
i++;
}
while(i<=10);
//printf(“Hello world!n”);
return 0;
}
In the program, test expression returns true codes inside the loop body are executes until become condition is false, so output here
Te program displays natural numbars 1 to given number
Program 2
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=1;
do{
printf(“%in”,i);
i++;
}
while(i>=10);
return 0;
}
When the above code is executed, it produces the following result
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int sum=0;
int n;
cout << "Enter the number as you wish" << endl;
cin>>n;
int i=1;
do{
sum=sum+i;
i++;
}while(i<=n);
cout<<"The sum of 1 to "<<n<<" : "<<sum;
getch();
return 0;
}
When the above code is executed, it produces the following result
Enter the number as you wish 100 The sum of 1 to 100: 5050
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.