Double the last digit of an inputted number


 c program to double the last digit of an inputted number. Example: Input 72564, Output 72568
(Assume that the last digit is less than 5)

Program:

#include<stdio.h>
int main()
{
          int num,temp;
          printf("enter num: ");
          scanf("%d",&num);
          temp=num%10;
          if(temp<5)
          {
                  num=num+temp;
                  printf("%d",num);
          }
          else
          printf("enter number such that its last digit is less than 5.");
          return 0;
}

Input:

12454

Output:

12458

 

No comments: