Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void fnc(int x)
  4. {
  5.     char str[255];
  6.     int i = 0, len = 0;
  7.     sprintf(str, "%d", x);
  8.     while (str[i] != 0)
  9.     {
  10.         len++;
  11.         i++;
  12.     }
  13.     for (i = 0; i < len; i++)
  14.         printf("%d", str[i] - '0');
  15. }
  16. int main()
  17. {
  18.     int i;
  19.     if (scanf("%d", &i) == 1)
  20.     {
  21.         if (i <= 0)
  22.         {
  23.             printf("Input error!");
  24.             return 1;
  25.         }
  26.         else if (i >= 0 && i <= 9)
  27.         {
  28.             printf("%d", i);
  29.             return 0;
  30.         }
  31.         else if (i >= 10)
  32.         {
  33.             fnc(i);
  34.             return 0;
  35.         }
  36.     }
  37.     else
  38.     {
  39.         printf("Input error!");
  40.         return 1;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement