Do – while loop in C language
In C language - A do while loop is similar to while loop with one exception that it executes the statements inside the body of do while before checking the condition. On the other hand in the while loop, first the condition is checked and then the statements in while loop are executed.
What is syntax of do- while loop in c language ?
Do
{
// Statements
} while (condition test);
1-Write a program in C language using do while loop.
#include<stdio.h>
#include<conio.h>
int main ()
{
int i=0;
clrscr();
do
{
prinitf(“ Value of variable i is :- %d \n”, i);
i++;
}
while(i<=3);
getch();
}
Output:-
3-write a C- language program to print “Hello world!!” using do- while loop.
#include<stdio.h>
#include<conio.h>
int main()
{
int i=1;
do
{
printf(“Hello world!” );
i++;
} while(i<=6);
getch();
}
Output:- Hello world!! Hello world!! Hello world!! Hello world!! Hello world!! Hello world!!
#include<iostream >
using namespace std;
int main()
{
int i=1;
do
{
Cout<<(“Hello world!” );
i++;
} while(i<=4);
getch();
}
Output:- Hello world!! Hello world!! Hello world!! Hello world!!
Class dowhile
{
public static void main (String args[] )
{
int i= 1;
do
{
System.out.println(“Hello java!!”);
i++;
}
while(i<5);
}
}
Output:-
In C language - A do while loop is similar to while loop with one exception that it executes the statements inside the body of do while before checking the condition. On the other hand in the while loop, first the condition is checked and then the statements in while loop are executed.
What is syntax of do- while loop in c language ?
Do
{
// Statements
} while (condition test);
1-Write a program in C language using do while loop.
do while loop program |
#include<stdio.h>
#include<conio.h>
int main ()
{
int i=0;
clrscr();
do
{
prinitf(“ Value of variable i is :- %d \n”, i);
i++;
}
while(i<=3);
getch();
}
Output:-
Value of variable i is :- 0
Value of variable i is :- 1
Value of variable i is :- 2
Value of variable i is :- 3
Program in c language using if-else condition.
#include<iostream.h>
using namespace std;
int main()
{
int i=1, num ;
clrscr();
cout<<“Enter a number :”;
cin>>(“%d”,&num) ;
do
{
cout<<“%d\n”,(number * i) ;
I++;
}
while(i<=10);
getch();
}
Output:-
Enter a number: 10
10 20 30 40 50 60 70 80 90 100
Write a C-language program for Addition,Substraction,Multiplication and Division.
Value of variable i is :- 1
Value of variable i is :- 2
Value of variable i is :- 3
Program in c language using if-else condition.
2-WAP to print table for the given number using do- while loop in C++ language.
#include<iostream.h>
using namespace std;
int main()
{
int i=1, num ;
clrscr();
cout<<“Enter a number :”;
cin>>(“%d”,&num) ;
do
{
cout<<“%d\n”,(number * i) ;
I++;
}
while(i<=10);
getch();
}
Output:-
Enter a number: 10
10 20 30 40 50 60 70 80 90 100
Write a C-language program for Addition,Substraction,Multiplication and Division.
3-write a C- language program to print “Hello world!!” using do- while loop.
#include<stdio.h>
#include<conio.h>
int main()
{
int i=1;
do
{
printf(“Hello world!” );
i++;
} while(i<=6);
getch();
}
Output:- Hello world!! Hello world!! Hello world!! Hello world!! Hello world!! Hello world!!
4- Write a program to print “Hello world!!” using do- while loop in C++.
#include<iostream >
using namespace std;
int main()
{
int i=1;
do
{
Cout<<(“Hello world!” );
i++;
} while(i<=4);
getch();
}
Output:- Hello world!! Hello world!! Hello world!! Hello world!!
5-Write a java program to print “Hello java!” in 5 times using do while condition.
Class dowhile
{
public static void main (String args[] )
{
int i= 1;
do
{
System.out.println(“Hello java!!”);
i++;
}
while(i<5);
}
}
Output:-
Hello java!!
Hello java!!
Hello java!!
Hello java!!
Write a C- program to compute the circumference of a circle and area of circle.#Programming near me
Hello java!!
Hello java!!
Hello java!!
Write a C- program to compute the circumference of a circle and area of circle.#Programming near me
0 Comments