Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int num, units, tens, hundreds, thousands;
  5.     printf("Please enter a positive 4 digit number :");
  6.     scanf_s("%d", &num);
  7.     units = num % 10;
  8.     tens = (num / 10) % 10;
  9.     hundreds = (num / 100) % 10;
  10.     thousands = num / 1000;
  11.     if (num < 0)
  12.     {
  13.         printf("%d is a negative number. Bye bye", num);
  14.         return 0;
  15.     }
  16.     if ((num >= 0 && num <= 999) || num > 9999)
  17.     {
  18.         printf("%d is not a 4 digit number. Bye bye", num);
  19.         return 0;
  20.     }
  21.     if ((thousands - hundreds) < 0 && (hundreds - thousands) == (tens - hundreds) && (tens - hundreds) == (units - tens))
  22.         printf("Increasing arithmetic sequence <from left to right>");
  23.     else if ((thousands - hundreds) > 0 && (thousands - hundreds) == (hundreds - tens) && (hundreds - tens) == (tens - units))
  24.         printf("Decreasing arithmetic sequence <from left to right>");
  25.     else if ((hundreds == thousands) && (hundreds == tens) && (tens == units))
  26.         printf("All 4 digits are the same");
  27.     else if ((thousands - hundreds) <= 0 && (tens - hundreds) >= 0 && (units - tens) >= 0)
  28.         printf("Increasing sequence <from left to right >");
  29.     else if ((thousands - hundreds) >= 0 && (hundreds - tens) >= 0 && (tens - units) >= 0)
  30.         printf("Decreasing sequence <from left to right>");
  31.     else
  32.     {
  33.         printf("Nondecreasing and nonincreasing sequence.");
  34.         return 0;
  35.     }
  36.  
  37.  
  38.  
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement