Write a program of prime number and reverse the number in C

Here we will learn how to write a program of prime number and reverse the number.

Let’s first we will discuss about the prime number

What is prime number ?

When the number is divided by 1 or itself is known as prime number

Example 2,3 5,7…etc are the prime numbers

Note: 0 and 1 are not prime number

Let’s start to the write the program.Here we will take input from the user.

#include<stdio.h>

void main( )

{

int i,n;

printf(“Enter the number: “);

scanf(“%d”,&n);

for(i=2;i<n;i++)

{

if(n%i==0)

{
printf(“number is not prime”);

break;

}

}

if(i==n)

{

printf(“number is prime”);

}

}

Output:

Enter the number: 5

number is prime

Now we will discuss about the reverse the number in C

Let’s start , if user give the input=12345 then output would be 54321

#include<stdio.h>

void main( )

{

int reverse=0,remainder,n;

printf(“Enter the number: “);

scanf(“%d”,&n);

if(n>0)

{

remainder=n%10;

reverse=reverse*10 + remainder;

n=n/10;

}

printf(“reverse number is=%d”,reverse);

}

Output:

Enter the number:12345

reverse number is=54321

sumankumar80

Hello Friends,I have written and developed this website because you can learn technology easily ,prepare for the placement and also for the any type of examination . By :Suman Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *