Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to remove the last digit from a number in C

2 Answers

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

unsigned int remove_last_digit(unsigned int n) {
    static char tmp[10];
     
    sprintf(tmp, "%d", n);
    
    tmp[strlen(tmp) - 1] = '\0';
     
    return atoi(tmp);
}
 
int main(void) {
    unsigned int n = 8405796;
    printf("n: %d\n", n);
 
    n = remove_last_digit(n);
     
    printf("n: %d\n", n);
     
    return 0;
}
 
 
   
/*
run:
   
n: 8405796
n: 840579
  
*/

 



answered Jan 15, 2021 by avibootz
0 votes
#include <stdio.h>

int main() {
    int n = 8405796;
    
    n = n / 10; // Remove the last digit

    printf("After removing the last digit: %d\n", n);

    return 0;
}


/*
run:

After removing the last digit: 840579

*/

 



answered Jul 30, 2025 by avibootz
...