# C Program to Remove Every Alternate Digit from a Number

## Introduction

In this post, I am going to write a c program to remove every alternate digit from a number. Basically, we will read a number from the console through the keyboard. After that, we will remove every alternate digit, i.e. position 2, 4, 6, etc. Let us see the expected output.

### Expected Output

As you can see in the above-expected output, we are removing every alternate digit from the number. For writing this program, let us perform the following steps.

1. Read a number from the console.
2. Reverse the number.
3. After reversing the number, using modulo and division operator.
4. Repeat steps 5, 6, 7 and 8 until the reversed number is greater than 0.
5. Find the remainder by using the modulo operator. Suppose that reversed number is 987654321.
6. Now, divide that number by 10 using the modulo operator.
7. We have to remove only those number which is at position 2, 4, 6 and so on. For this, we will use the counter variable count and if the value of that count variable is even, then we will remove that number.
8. Now, make the number less by 1. How? Just divide the number by 10 and you will get the quotient.

I hope you have understood the above steps. Now, see the following program.

## C Program to Remove Every Alternate Digit from a Number

``````#include <stdio.h>
#include <stdlib.h>
int main()
{
int rem,rev=0,rnum=0,count=0;;
long int n,an;
printf("Enter any Number\n");
scanf("%ld",&n);
an=n;
while(n>0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
while(rev>0)
{
rem=rev%10;
count++;
if(count%2==1)
rnum=rnum*10+rem;
rev=rev/10;
}
printf("Original Number = %ld\n",an);
printf("Number after removing alternate digits = %d",rnum);
return 0;
}
``````

In the above c program, there are six variables of type int and long int. They are

1. rem is for the remainder,
2. rev=0 will store reverse number,
3. rnum=0 is for storing number after removing alternate digit,
4. count=0 is for counting to check whether the position is even or odd,
5. n is the number,
6. an is the actual number

I hope you have understood the above program. If you have any difficulty understanding this program, please let me know.

Thank you.