Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int num, units, tens, hundreds, thousands;
- printf("Please enter a positive 4 digit number :");
- scanf_s("%d", &num);
- units = num % 10;
- tens = (num / 10) % 10;
- hundreds = (num / 100) % 10;
- thousands = num / 1000;
- if (num < 0)
- {
- printf("%d is a negative number. Bye bye", num);
- return 0;
- }
- if ((num >= 0 && num <= 999) || num > 9999)
- {
- printf("%d is not a 4 digit number. Bye bye", num);
- return 0;
- }
- if ((thousands - hundreds) < 0 && (hundreds - thousands) == (tens - hundreds) && (tens - hundreds) == (units - tens))
- printf("Increasing arithmetic sequence <from left to right>");
- else if ((thousands - hundreds) > 0 && (thousands - hundreds) == (hundreds - tens) && (hundreds - tens) == (tens - units))
- printf("Decreasing arithmetic sequence <from left to right>");
- else if ((hundreds == thousands) && (hundreds == tens) && (tens == units))
- printf("All 4 digits are the same");
- else if ((thousands - hundreds) <= 0 && (tens - hundreds) >= 0 && (units - tens) >= 0)
- printf("Increasing sequence <from left to right >");
- else if ((thousands - hundreds) >= 0 && (hundreds - tens) >= 0 && (tens - units) >= 0)
- printf("Decreasing sequence <from left to right>");
- else
- {
- printf("Nondecreasing and nonincreasing sequence.");
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement