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 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 by avibootz
edited Apr 22 by avibootz
...