[go: up one dir, main page]

0% found this document useful (0 votes)
8 views5 pages

Do while loop

The document contains several C programming examples, including programs to reverse a number, check for palindromes, and determine if a number is an Armstrong number. It also explains the do-while loop and provides examples for printing even and odd numbers, as well as patterns using nested loops. Each program is accompanied by its code implementation.

Uploaded by

Elsing tamang
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)
8 views5 pages

Do while loop

The document contains several C programming examples, including programs to reverse a number, check for palindromes, and determine if a number is an Armstrong number. It also explains the do-while loop and provides examples for printing even and odd numbers, as well as patterns using nested loops. Each program is accompanied by its code implementation.

Uploaded by

Elsing tamang
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
You are on page 1/ 5

1. WAP to reverse to find the reverse of a given number.

#include<stdio.h>
#include<conio.h>
int main()
{
int n,r,s=0;
printf("Enter any number");
scanf("%d",&n);
while(n>0)
{
r= n%10;
s=s*10+r;
n=n/10;

}
printf("Revers=%d",s);
getch();
}
2. WAP to check if the given number is palindrome or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,r,s=0,c;
printf("Enter any number");
scanf("%d",&n);
c=n;
while(n!=0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(c==s)
{
printf("Given number is pallindrome number");
}
else
{
printf("Given number is not pallindrome number");
}
getch();
}
3. WAP to find the whether a given number is Armstrong or not.
#include<stdio.h>
#include<conio.h>
int main()
{
int n,r,s=0,c;
printf("Enter any number");
scanf("%d",&n);
c=n;
while(n!=0)
{
r=n%10;
s=s + r*r*r;
n=n/10;
}
if(c==s)
{
printf("given number is Armstrong number");
}
else
{
printf("Given number is not Armstrong number");
}
getch();
}
Do while loop
This is a post-conditioned loop i.e. first the statements inside the loop are executed once and then the
condition is checked. If the condition is true, the process is repeated till the condition is true, otherwise
loop is terminated.
Syntax:
Initialization;
do
{
Statements;
.................
................
}
While(condition);
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
i =1;
do
{
printf("%d\t", i);
i=i+1;
}
while(i<=10);
getch();
}

4. WAP to print even number between 2 to 10 using do while loop.


#include<stdio.h>
#include<conio.h>
int main()
{
int i;
i =2;
do
{
printf("%d\t", i);
i=i+2;
}
while(i<=10);
getch();
}
5. WAP to print odd number between 1 to 10.
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
i =1;
do
{
printf("%d\t", i);
i=i+2;
}
while(i<=10);
getch();
}
6. WAP to display:
1
22
333
4444
55555

#include<stdio.h>
#include<conio.h>
int main()
{
int i,j;
for (i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
getch();
}

1
12
123
1234
12345
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j;
for (i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
*
**
***
****
*****

#include<stdio.h>
#include<conio.h>
int main()
{
int i,j;
for (i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

You might also like