## prime numbers:

prime numbers are divisible by only 1 and that number itself. Eg.in this program, as per divisions, integer number 5 can be divided by 1 and integer number 5 which is nothing but original number so it is prime number. 2 is the only even prime number.
prime number:2,3,5,7,11,13,17,19,23,29,…

## logic:

Below program to find prime number takes user input and then if condition inside for loop checks whether number is divisible by smaller number than input number which is 1 or number itself.

``````#include<stdio.h>
#include<conio.h>
#include<math.h>
void printprimes();
int checkprimes(int num);
void main()
{
int i;
int flag;
printf("\n Prime numbers from 1 to 100:");
printprimes();
getch();
}
void printprimes()
{
int i,j;
for(i=2;i<=100;i++)
{
if(checkprimes(i));
printf("%d\t",i);
}
}
int checkprimes(int num)
{
int j;
for(j=2;j<=sqrt(num);j++)
{
if(num%j==0)
return 0;
}
return 1;
}
``````

Ouput:

``````  ```Similar programs:
You might also like to see:```

Program to find prime number using function

## Define Palindrome number:

Palindrome number is viewed with same value after we do reversal of its digits.
Example: Say number is, number = 212, then reversal of its digits will make output be like number = 212. so that here 212 is a palindrome.

``````#include
#include
int palindrome(int val);
int rever=0,remain=0;
void main()
{
int val;
printf("\n Enter a number: ");
scanf("%d",&val);
if(val==palindrome(val))
{
printf("\n %d is a palindrome",val);
}
else
{
printf("\n %d is not a palindrome",val);
}
getch();
}
int palindrome(int val)
{
for(;val>0;val=val/10)
{
remain=val%10;
rever=rever*10+remain;
}
return rever;
}
``````

Ouput:

``````Enter a number: 212
212 is a palindrome
``````

## Palindrome number:

It is an integer number that stays same after reversal of its digits.
Example: say value of integer is, N = 121, then output will be 121. So that value 121 is called palindrome.

``````#include
#include
int palindrome(int val);
int rever=0,remain=0;
void main()
{
int num;
printf("\n Enter a number: ");
scanf("%d",&val);
if(val==palindrome(val))
{
printf("\n %d is a palindrome",val);
}
else
{
printf("\n %d is not a palindrome",val);
}
getch();
}
int palindrome(int val)
{
do
{
remain=val%10;
rever=rever*10+remain;
val=val/10;
}while(val>0);
return rever;
}
``````

Ouput:

``````Enter a number: 12121
12121 is a palindrome
``````

## Palindrome number is:

It is an integer that has same value even after the reversal of its digits.
Example: say the input, Number = 12121, after reversal is done,then Number = 12121. So that 12121 is called palindrome.

``````#include
#include
int palindrome(int val);
int rever=0,remain=0;
void main()
{
int num;
printf("\nEnter a number: ");
scanf("\n%d",&val);
if(val==palindrome(val))
{
printf("\n%d is a palindrome no",val);
}
else
{
printf("\n%d is not a palindrome no",val);
}
getch();
}
int palindrome(int val)
{
while(val)
{
remain=val%10;
rever=rever*10+remain;
val=val/10;
}
return rever;
}
``````

Ouput:

``````Enter a number: 12321
12321 is a palindrome no
``````

## Program

### C Program to reverse digits of a number using for loop

``````#include
#include
void main()
{
int val;
int rever=0, remain=0;
printf("\n Enter a number: ");
scanf("%d",&val);
for(;val>0;val=val/10)
{
remain = val%10;
rever = rever*10+remain;
}

printf("\n reverse of number is = %d",rever);
getch();
}
``````

### Output

``````Enter a number: 132
reverse of number is = 231
``````

## Program

### Program in C for reversal of digits of a number using do while loop

``````#include
#include
void main()
{
int val;
int rever=0, remain=0;
printf("\nEnter a number: ");
scanf("\n%d",&val);
do
{
remain = val%10;
rever = rever*10+remain;
val = val/10;
}while(val>0);

printf("\nreverse of the number = %d",rever);
getch();
}
``````

### Output

``````Enter a number: 254
reverse of the number = 452
``````

## Program

### Program to reverse digits of a number using while loop in c

``````#include<stdio.h>
#include<conio.h>
void main()
{
int num;
int rev=0, rem=0;
printf("n Enter a number: ");
scanf("%d",&num);
while(num>0)
{
rem = num%10;
rev = rev*10+rem;
num = num/10;
}
printf("n reverse number = %d",rev);
getch();
}
``````

### Output

``````Enter a number: 123
Reverse number = 321
``````

## c program to check whether given number is armstrong number or not using for loop

``````#include<stdio.h>
#include<conio.h>
void main()
{
int num, n, rem;
int cube=0, sum=0;
printf("n Enter a number: ");
scanf("%d",&num);
n = num;
for(;n>0;n=n/10)
{
rem = n%10;
cube = rem*rem*rem;
sum = sum + cube;
}
if(num==sum)
{
printf("n %d is armstrong number",num);
}
else
{
printf("n %d not armstrong number",num);
}
getch();
}
``````

Ouput:

``````Enter a number: 407
407 is armstrong number
``````

## Armstrong numbers:

Input : 153.
Calculating armstrong number: 153 =(1*1*1)+(5*5*5)+(3*3*3)= 1+125+27 =153

If input equals output, 153==153, 153 is armstrong number.

``````#include<stdio.h>
#include<conio.h>
void main()
{
int num, n, rem;
int cube=0, sum;
printf("n Armstrong numbers between 1 and 1000 are: n");
for(num=1;num<=1000;num++)
{
sum=0;
n=num;
while(n>0)
{
rem=n%10;
cube=rem*rem*rem;
sum=sum+cube;
n=n/10;
}
if(num==sum)
{
printf("n%d is armstrong number",num);
}
getch();
}
``````

Ouput:

``````Armstrong numbers between 1 and 1000 are:
1 is armstrong number
153 is armstrong number
370 is armstrong number
371 is armstrong number
407 is armstrong number
``````

## Armstrong numbers are:

Input :say value is 370.
When doing calculation for armstrong number:
370 is equal to (3*3*3)+(7*7*7)+(0*0*0) so output is 27+343+0 = 370
If input value is similar with output which is 370==370, then 370 is called an armstrong no.

``````#include
#include
void main()
{
int number, j, remain;
int cube=0, sum;
printf("\n Armstrong numbers between the limit from 1 to 500 are: \n");
for(number=0;number<=999;number++)
{
sum=0;
j=number;
while(j>0)
{
remain=j%10;
cube=remain*remain*remain;
sum=sum+cube;
j=j/10;
}
if(number==sum)
printf("\n%d is an armstrong no.",number);
}
getch();
}

``````

Ouput:

``````Armstrong numbers between the limit from 1 to 500 are:
1 is an armstrong no.
153 is an armstrong no.
370 is an armstrong no.
371 is an armstrong no.
407 is an armstrong no.
``````
error: Content is protected !!