Delete the second last digit of an inputted number


C program to delete the second last digit.

Sample Input 12345, Output 1235
 

Program:

#include<stdio.h>
int main()
{
        int num,temp1,temp2;
        printf("enter num: ");
        scanf("%d",&num);
        temp1=num%10;                  /* store last digit in temp1   */
        num=num/10;                       /* making number one digit shorter   */
        temp2=num%10;                  /* store the second last digit in temp2   */
        num=num-temp2+temp1; /* add the last digit and subtract second last digit to shorter number  */
          printf("%d",num);
          return 0;
}

4 comments:

Unknown said...
This comment has been removed by the author.
Anonymous said...

n = -10

Anonymous said...

when we use -10

then your program does run...try to modify your code

Anonymous said...

Stupid