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 the N digit from a number in C

1 Answer

0 votes
#include <stdio.h>
#include <math.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 n_digit) { 
    int rev_new_num = 0; 
    int l = log10(num) + 1; 
      
    for (int i = 0; num != 0; i++) { 
        int digit = num % 10; 
        num = num / 10; 
    
        if (i != l - n_digit) {
            rev_new_num = (rev_new_num * 10) + digit; 
        } 
    } 
       
    return reverse_number(rev_new_num); 
} 
int main() {
    int num = 37598; 
    
    printf("%i\n", delete_digit(num, 3));
    printf("%i\n", delete_digit(num, 1));
    printf("%i\n", delete_digit(num, 5));
}
    
 
  
/*
run:
    
3798
7598
3759
    
*/

 




answered Apr 22, 2019 by avibootz
edited Apr 22, 2019 by avibootz
...