14. Program to print numbers from 1 to n using while loop.
#while_loop
@C_Codings
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1, n;
clrscr();
printf("Enter n : ");
scanf("%d", &n);
while(i<=n)
{
printf("%d\t",i);
i++;
}
getch();
}#while_loop
@C_Codings
16. Program to print first n even numbers.
#while_loop
@C_Codings
#include<stdio.h>
#include<conio.h>
void main()
{
int i = 2, n;
//to print odd numbers set variable i = 1
clrscr();
printf("Enter n : ");
scanf("%d", &n);
while(i<=n)
{
printf("%d\t", i);
i = i + 2;
}
getch();
}#while_loop
@C_Codings
17. Program to accept a number and print that number in reverse order.
Ex:- 1024
Output:- 4201
#while_loop
@C_Codings
Ex:- 1024
Output:- 4201
#include<stdio.h>
#include<conio.h>
void main()
{
int reminder, n;
clrscr();
printf("Enter n : ");
scanf("%d", &n);
while(n>0)
{
reminder=n%10;
printf("%d", reminder);
n=n/10;
}
getch();
}#while_loop
@C_Codings
18. Program to accept a number and print sum of itβs digits.
#while_loop
@C_Codings
#include<stdio.h>
#include<conio.h>
void main()
{
int reminder, sum=0, n;
clrscr();
printf("Enter n : ");
scanf("%d", &n);
while(n>0)
{
reminder = n % 10;
sum = sum + reminder;
n = n / 10;
}
printf("Sum of digits : %d",sum);
getch();
}#while_loop
@C_Codings
19. Program to take a number from user and check whether it is Armstrong number or not.
#while_loop
@C_Codings
#include<stdio.h>
#include<conio.h>
void main()
{
int i=2, temp, rem, sum=0, n;
clrscr();
printf("Enter n : ");
scanf("%d", &n);
temp = n;
while(n>0)
{
rem = n%10;
sum = sum+(rem*rem*rem);
n = n/10;
}
if(temp == sum)
printf("Entered number is an Armstrong Number");
else
printf("Entered number is not an Armstrong Number");
getch();
}#while_loop
@C_Codings