Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

10,405 questions

14,169 answers

573 users

How to remove specific digit from a number in C

1 Answer

0 votes
#include <stdio.h>
    
int reverse_number(int num) {
    int reminder = 0, reverse = 0;
    while (num != 0) {    
        reminder = num % 10;      
        reverse = reverse * 10 + reminder;    
        num /= 10;    
    }
    return reverse;
} 
    
int delete_digit(int num, int d) { 
    int rev_new_num = 0; 
       
    while (num != 0) { 
        int digit = num % 10; 
        num = num / 10; 
     
        if (digit != d) { 
            rev_new_num = (rev_new_num * 10) + digit; 
        } 
    } 
   
    return reverse_number(rev_new_num); 
} 
int main() {
    int num = 375938; 
     
    printf("%i\n", delete_digit(num, 3));
    printf("%i\n", delete_digit(num, 8));
    printf("%i\n", delete_digit(num, 5));
}
     
     
/*
run:
     
7598
37593
37938
     
*/

 




answered Apr 21 by avibootz
edited Apr 22 by avibootz
...