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

Control Statement

The document explains the while loop control statement in C programming, detailing its syntax and providing examples. It includes four C programs: one to print the first 10 natural numbers, another to check if a number is prime or composite, a third to determine if a number is a palindrome, and a fourth to verify if a number is an Armstrong number. Each program demonstrates the use of the while loop to perform its respective task.

Uploaded by

rs8731549
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 views2 pages

Control Statement

The document explains the while loop control statement in C programming, detailing its syntax and providing examples. It includes four C programs: one to print the first 10 natural numbers, another to check if a number is prime or composite, a third to determine if a number is a palindrome, and a fourth to verify if a number is an Armstrong number. Each program demonstrates the use of the while loop to perform its respective task.

Uploaded by

rs8731549
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/ 2

Control statement

While loop
While loop first checks whether the initial condition is true or false and finding it to be true, it will enter the loop and
execute the statement.
Syntax
Initialization
While(condition)
{
Statement 1;
…………………..;
Statement n;
}
1. Write a C program to find the first 10 natural number using while loop.
#include <stdio.h>
#include <stdlib.h>

int main()
{
int num=1;
while(num<=10)
{
printf("%d\t",num);
num++;
}
return 0;
}
2. Write a C program to checks whether the entered number by user is prime or composite using while loop.
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,num;
printf("Enter the number:\n");
scanf("%d",&num);
i=2;
while(i<=num-1)
{
if(num%i==0)
{
printf("%d is a composite number",num);
break;
}
i++;
}
if(i==num)
printf("%d is a prime number",num);
return 0;
}
3. Write a C program to check whether the entered number by the user is palindrome or not.
#include <stdio.h>
#include <stdlib.h>

int main()
{
int n, rev=0,digit,num;
printf("Enter a number:\n");
scanf("%d",&n);
num=n;
while(n!=0)
{
digit=n%10;
rev=rev*10+digit;
n=n/10;
}
if(rev==num)
printf("It is a palindrome number",num);
else
printf("It is not a palindrome number",num);
return 0;
}
4. Write a C program to check whether the entered number by user is Armstrong or not.
#include <stdio.h>
#include <stdlib.h>
#include<math.h>

int main()
{
int n, sum=0,a,r;
printf("Enter a number:\n");
scanf("%d",&n);
a=n;
while(n!=0)
{
r=n%10;
sum=sum+pow(r,3);
n=n/10;
}
if(sum==a)
printf("%d is an armstrong number",a);
else
printf("%d is an armstrong number",a);
return 0;
}

You might also like