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.
Also Read: Switch Case in C Program to Calculate Area of Circle and Triangle
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.
- Read a number from the console.
- Reverse the number.
- After reversing the number, using modulo and division operator.
- Repeat steps 5, 6, 7 and 8 until the reversed number is greater than 0.
- Find the remainder by using the modulo operator. Suppose that reversed number is 987654321.
- Now, divide that number by 10 using the modulo operator.
- 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.
- 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.
Also Read: C Program to Print Multiples of 5 using do-while loop
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
- rem is for the remainder,
- rev=0 will store reverse number,
- rnum=0 is for storing number after removing alternate digit,
- count=0 is for counting to check whether the position is even or odd,
- n is the number,
- 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.
Some Important C Programs
- C Program to Remove Zeros from a number
- The while loop in C Programming
- Reverse a Number using getchar and putchar function in c
- C Program to Print Numbers Except Multiples of n
- C Program to Remove White Spaces and Comments from a File
- Program in C to Find Longest Line in a File
- Palindrome in C using Pointers
- Insert and Delete element in Array in C using switch case
- C Program to Add Alternate Elements of a 2D Array
- Arrays in C for Complete Beginners
- C Program to Find Area of a Circle using Preprocessor