## C program to swap two numbers using bitwise operators

#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
printf("n Enter values for a and b:");
scanf("%d%d",&a,&b);
printf("Before swapping: n");
printf("a=%d, b=%d\n",a,b);
a = a^b;
b = a^b;
a = a^b;
printf("After swapping: n");
printf("a=%d,b=%d\n",a,b);
getch();
}

output:

Enter values for a and b: 10 20
Before swapping:
a=10, b=20
After swapping:
a=20, b=10

## C program to print characters in a string and address of each character

#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
char str[10];
printf("n Enter any string:");
scanf("%s",&str);
while(str[i]!='')
{
printf("character = %ct",str[i]);
}
getch();
}

Ouput:

Enter a string: clessons
character = c   address = FFEC
character = l   address = FFED
character = e   address = FFEE
character = s   address = FFEF
character = s   address = FFF0
character = o   address = FFF1
character = n   address = FFF2
character = s   address = FFF3

## 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:

When we reverse digits of number from right to left, then number can be seen as similar number it was previously then it is called palindrome number.
Example: suppose number considered is 121 and after we do reversal then digits of this number still stay same, so that 121 is palindrome number

#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 no",val);
}
else
{
printf("\n %d is not a palindrome no",val);
}
getch();
}

int palindrome(int val)
{
if(val)
{
remain=val%10;
rever=rever*10+remain;
palindrome(val/10);
}
return rever;
}

Ouput:

Enter a number: 16461
16461 is a palindrome no

## 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

## Palindrome number:

palindrome number can also be definded as a number which is equal to number after reversing its digits.
Example: for e.g. input is 12121, and after reversal of its digits, input number will be 12121.

## Logic:

1.Input a number
2.Reverse its digits
3.match reversed number against input number

#include<stdio.h>
#include<conio.h>
int ispalindrome(int num);
int reverse(int n);
int rev=0,rem=0;
void main()
{
int num;
printf("n Enter a number: ");
scanf("%d",&num);
if(ispalindrome(num))
{
printf("n %d is palindrome number",num);
}
else
{
printf("n %d is not palindrome number,"num);
}
getch();
}

int ispalindrome(int num)
{
if(num==reverse(num))
{
return 1;
}
else
{
return 0;
}
}

int reverse(int n)
{
if(n)
{
rem=n%10;
rev=rev*10+rem;
reverse(n/10);
}
return rev;
}

Ouput:

Enter a number: 10201
10201 is palindrome number

## c program to find reverse of a number using recursion

#include<stdio.h>
#include<conio.h>
int reverse(int num);
void main()
{
int num, r=0;
printf("n Enter a number: ");
scanf("%d",&num);
r = reverse(num);
printf("n Reverse number = %d",r);
getch();

}
int rev = 0, rem = 0;
int reverse(int num)
{
if(num)   {
rem=num%10;
rev=rev*10+rem;
reverse(num/10);
}
return rev;
}

Ouput:

Enter a number: 371
Reverse number = 173

## 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

error: Content is protected !!