Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and work.

aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing
BlueHost Web Hosting

Profollica™ is a standout product in the hair regrowth industry.

New Arrival!  Shop NOW for metal eyeglasses at GlassesShop.com!

Bonsai Boy of New York Bonsai Trees and Accessories

DreamCloud The Comfortable Luxury Mattress Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Liquid Web Cloud VPS Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

13,696 questions

18,622 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, 2019 by avibootz
edited Apr 22, 2019 by avibootz
...